diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index c9e23cbee1..8a22ce452b 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -4679,8 +4679,13 @@ void for_each_node_effectively_contained_in_range(GC::Ptr range, Fun return; // A node can still be "effectively contained" in range even if it's not actually contained within the range; so we - // need to do an inclusive subtree traversal since the common ancestor could be matched as well. - range->common_ancestor_container()->for_each_in_inclusive_subtree([&](GC::Ref descendant) { + // need to traverse the highest effectively contained ancestor of the common ancestor container. + // See: https://w3c.github.io/editing/docs/execCommand/#effectively-contained + GC::Ref traversal_root = range->common_ancestor_container(); + while (traversal_root->parent() && is_effectively_contained_in_range(*traversal_root->parent(), *range)) + traversal_root = *traversal_root->parent(); + + traversal_root->for_each_in_inclusive_subtree([&](GC::Ref descendant) { if (!is_effectively_contained_in_range(descendant, *range)) { // NOTE: We cannot skip children here since if a descendant is not effectively contained within a range, its // children might still be. diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/run/backcolor.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/run/backcolor.txt index 36842a94eb..9318143ed2 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/editing/run/backcolor.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/editing/run/backcolor.txt @@ -2,8 +2,7 @@ Harness status: OK Found 1026 tests -1025 Pass -1 Fail +1026 Pass Pass [["backcolor","#00FFFF"]] "foo[]bar": execCommand("backcolor", false, "#00FFFF") return value Pass [["backcolor","#00FFFF"]] "foo[]bar" checks for modifications to non-editable content Pass [["backcolor","#00FFFF"]] "foo[]bar" compare innerHTML @@ -914,7 +913,7 @@ Pass [["backcolor","#00FFFF"]] "foo[bar] Pass [["backcolor","#00FFFF"]] "foo[bar]baz" queryCommandValue("backcolor") after Pass [["backcolor","#00FFFF"]] "foo[bar]baz": execCommand("backcolor", false, "#00FFFF") return value Pass [["backcolor","#00FFFF"]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["backcolor","#00FFFF"]] "foo[bar]baz" compare innerHTML +Pass [["backcolor","#00FFFF"]] "foo[bar]baz" compare innerHTML Pass [["backcolor","#00FFFF"]] "foo[bar]baz" queryCommandIndeterm("backcolor") before Pass [["backcolor","#00FFFF"]] "foo[bar]baz" queryCommandState("backcolor") before Pass [["backcolor","#00FFFF"]] "foo[bar]baz" queryCommandValue("backcolor") before diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@1001-2000.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@1001-2000.txt index 6cd0f8a8b3..05a0b1ad49 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@1001-2000.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@1001-2000.txt @@ -2,8 +2,8 @@ Harness status: OK Found 1000 tests -984 Pass -16 Fail +994 Pass +6 Fail Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") after @@ -196,7 +196,7 @@ Pass [["stylewithcss","false"],["bold",""]] "bar [baz] qoz" que Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -212,7 +212,7 @@ Pass [["stylewithcss","true"],["bold",""]] "foo Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -228,7 +228,7 @@ Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -244,7 +244,7 @@ Pass [["stylewithcss","true"],["bold",""]] "foo Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -260,7 +260,7 @@ Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -276,7 +276,7 @@ Pass [["stylewithcss","true"],["bold",""]] "foo Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -292,7 +292,7 @@ Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -308,7 +308,7 @@ Pass [["stylewithcss","true"],["bold",""]] "foo Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -324,7 +324,7 @@ Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before @@ -340,7 +340,7 @@ Pass [["stylewithcss","true"],["bold",""]] "foo Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo[bar]baz" queryCommandValue("stylewithcss") before diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@2001-3000.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@2001-3000.txt index f52bb158d0..6052c04382 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@2001-3000.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@2001-3000.txt @@ -2,8 +2,8 @@ Harness status: OK Found 1000 tests -989 Pass -11 Fail +993 Pass +7 Fail Fail [["bold",""]] "foo[barbaz}" compare innerHTML Pass [["bold",""]] "foo[barbaz}" queryCommandIndeterm("bold") before Pass [["bold",""]] "foo[barbaz}" queryCommandState("bold") before @@ -471,7 +471,7 @@ Pass [["bold",""]] "foo[bar]" quer Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "foo{bar}baz" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz" queryCommandValue("stylewithcss") before @@ -487,7 +487,7 @@ Pass [["stylewithcss","true"],["bold",""]] "foo{bar}baz": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "foo{bar}baz": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "foo{bar}baz" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "foo{bar}baz" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "foo{bar}baz" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "foo{bar}baz" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo{bar}baz" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "foo{bar}baz" queryCommandValue("stylewithcss") before @@ -535,7 +535,7 @@ Pass [["stylewithcss","false"],["bold",""]] "[foobarb Pass [["stylewithcss","true"],["bold",""]] "[foo]": execCommand("stylewithcss", false, "true") return value Pass [["stylewithcss","true"],["bold",""]] "[foo]": execCommand("bold", false, "") return value Pass [["stylewithcss","true"],["bold",""]] "[foo]" checks for modifications to non-editable content -Fail [["stylewithcss","true"],["bold",""]] "[foo]" compare innerHTML +Pass [["stylewithcss","true"],["bold",""]] "[foo]" compare innerHTML Pass [["stylewithcss","true"],["bold",""]] "[foo]" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "[foo]" queryCommandState("stylewithcss") before Pass [["stylewithcss","true"],["bold",""]] "[foo]" queryCommandValue("stylewithcss") before @@ -551,7 +551,7 @@ Pass [["stylewithcss","true"],["bold",""]] "[foo]< Pass [["stylewithcss","false"],["bold",""]] "[foo]": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "[foo]": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "[foo]" checks for modifications to non-editable content -Fail [["stylewithcss","false"],["bold",""]] "[foo]" compare innerHTML +Pass [["stylewithcss","false"],["bold",""]] "[foo]" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "[foo]" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "[foo]" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "[foo]" queryCommandValue("stylewithcss") before diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@3001-last.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@3001-last.txt index 2912ba5ad8..005c6b0bd7 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@3001-last.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/editing/run/bold@3001-last.txt @@ -2,8 +2,8 @@ Harness status: OK Found 44 tests -39 Pass -5 Fail +38 Pass +6 Fail Pass [["stylewithcss","false"],["bold",""]] "fo[ob]ar" queryCommandIndeterm("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "fo[ob]ar" queryCommandState("stylewithcss") before Pass [["stylewithcss","false"],["bold",""]] "fo[ob]ar" queryCommandValue("stylewithcss") before @@ -27,7 +27,7 @@ Pass [["stylewithcss","false"],["bold",""]] "abc[d[def]ghi": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "abc[def]ghi": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "abc[def]ghi" checks for modifications to non-editable content -Pass [["stylewithcss","false"],["bold",""]] "abc[def]ghi" compare innerHTML +Fail [["stylewithcss","false"],["bold",""]] "abc[def]ghi" compare innerHTML Pass [["stylewithcss","false"],["bold",""]] "abc[def]ghi": execCommand("stylewithcss", false, "false") return value Pass [["stylewithcss","false"],["bold",""]] "abc[def]ghi": execCommand("bold", false, "") return value Pass [["stylewithcss","false"],["bold",""]] "abc[def]ghi" checks for modifications to non-editable content