Skip to content

Truly independent web browser

LibWeb: Preserve overrides when taking the action of a command

Andreas Kling6b4b27b37805
diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
index a203752e027..3ab64b478d6 100644
--- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
+++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
@@ -5285,7 +5285,21 @@ RefPtr<CSS::StyleValue const> resolved_value(GC::Ref<DOM::Node> node, CSS::Prope
void take_the_action_for_command(DOM::Document& document, Utf16FlyString const& command, Utf16View value)
{
auto const& command_definition = find_command_definition(command);
+
+ // https://w3c.github.io/editing/docs/execCommand/#preserves-overrides
+ // If a command preserves overrides, then before taking its action, the user agent must record current overrides.
+ Vector<RecordedOverride> overrides;
+ if (command_definition->preserves_overrides)
+ overrides = record_current_overrides(document);
+
command_definition->action(document, value);
+
+ // After taking the action, if the active range is collapsed, it must restore states and values from the recorded
+ // list.
+ if (!overrides.is_empty()) {
+ if (auto range = active_range(document); range && range->collapsed())
+ restore_states_and_values(document, overrides);
+ }
}
bool value_contains_keyword(CSS::StyleValue const& value, CSS::Keyword keyword)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt
index 30c4172a629..27fda67fb34 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt
@@ -2,12 +2,11 @@ Harness status: OK
Found 138 tests
-132 Pass
-6 Fail
+138 Pass
Pass <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:nowrap; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -30,7 +29,7 @@ Pass <div contenteditable><p style="display:block; white-space:nowrap">a[]bc</p>
Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -53,7 +52,7 @@ Pass <div contenteditable><p style="display:inline; white-space:nowrap">a[]bc</p
Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -76,7 +75,7 @@ Pass <div contenteditable><p style="display:inline-block; white-space:nowrap">a[
Pass <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:nowrap; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
@@ -99,7 +98,7 @@ Pass <div contenteditable><p style="display:block; white-space:nowrap">a[]bc</p>
Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
@@ -122,7 +121,7 @@ Pass <div contenteditable><p style="display:inline; white-space:nowrap">a[]bc</p
Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt
index d79452ecefa..66d9a332347 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt
@@ -2,12 +2,12 @@ Harness status: OK
Found 138 tests
-132 Pass
-6 Fail
+134 Pass
+4 Fail
Pass <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:pre">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:block"><div style="white-space:pre">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -76,7 +76,7 @@ Pass <div contenteditable><p style="display:inline-block; white-space:pre">a[]bc
Pass <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre; display:block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre; display:block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:pre">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:block"><div style="white-space:pre">[]abc</div></div> (defaultParagraphSeparator: p)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt
index 46f644a1c50..8dcd2a5ba43 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt
@@ -2,12 +2,12 @@ Harness status: OK
Found 138 tests
-132 Pass
-6 Fail
+134 Pass
+4 Fail
Pass <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-line; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:pre-line">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:block"><div style="white-space:pre-line">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -76,7 +76,7 @@ Pass <div contenteditable><p style="display:inline-block; white-space:pre-line">
Pass <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-line; display:block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-line; display:block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-line; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:pre-line">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:block"><div style="white-space:pre-line">[]abc</div></div> (defaultParagraphSeparator: p)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt
index 28d31f8a5ec..d9a20e2a6bb 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt
@@ -2,12 +2,12 @@ Harness status: OK
Found 138 tests
-132 Pass
-6 Fail
+134 Pass
+4 Fail
Pass <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-wrap; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:pre-wrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:block"><div style="white-space:pre-wrap">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -76,7 +76,7 @@ Pass <div contenteditable><p style="display:inline-block; white-space:pre-wrap">
Pass <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-wrap; display:block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-wrap; display:block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-wrap; display:block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:block"><div style="white-space:pre-wrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:block"><div style="white-space:pre-wrap">[]abc</div></div> (defaultParagraphSeparator: p)