[webkit-changes] [WebKit/WebKit] fa3afa: mail.yahoo.com: caret jumps to the start of the ed...
Wenson Hsieh
noreply at github.com
Sun Oct 27 11:35:12 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: fa3afaa2ad393deee894e62a7dc2ef11e7be50d3
https://github.com/WebKit/WebKit/commit/fa3afaa2ad393deee894e62a7dc2ef11e7be50d3
Author: Wenson Hsieh <wenson_hsieh at apple.com>
Date: 2024-10-27 (Sun, 27 Oct 2024)
Changed paths:
M LayoutTests/editing/execCommand/outdent-break-with-style-expected.txt
M LayoutTests/editing/execCommand/outdent-regular-blockquote-expected.txt
M LayoutTests/editing/execCommand/outdent-selection-expected.txt
M LayoutTests/editing/execCommand/unindent-nested-blockquote-with-inner-div-expected.txt
M LayoutTests/imported/w3c/web-platform-tests/editing/run/outdent_1-1000-expected.txt
M LayoutTests/imported/w3c/web-platform-tests/editing/run/outdent_2001-last-expected.txt
M Source/WebCore/editing/IndentOutdentCommand.cpp
Log Message:
-----------
mail.yahoo.com: caret jumps to the start of the editor after outdenting out of a blockquote
https://bugs.webkit.org/show_bug.cgi?id=282142
rdar://138081308
Reviewed by Ryosuke Niwa.
In Yahoo Mail, when outdenting to break out of a blockquote element on a line with no content, the
selection is always reset to the top of the editable root. Suppose we're outdenting in a simple DOM
tree on Yahoo:
```
--- Safari, before outdenting
<DIV contenteditable> # Yahoo's root editable element
<BLOCKQUOTE>
<DIV>
Some text
<DIV>
# Selection is here.
<BR>
```
1. When clicking on the outdent menu item in Yahoo Mail's UI, Yahoo triggers the `Outdent` editing
command. This executes as expected, and places the ending selection in the correct location
(depicted below).
```
--- Safari, after outdenting
<DIV contenteditable> # Yahoo's root editable element
<BLOCKQUOTE>
<DIV>
Some text
# Selection is here
<BR>
```
2. However, immediately after this happens, the menu dismisses, which runs some other JavaScript
that then attempts to "fix up" the DOM selection. This JavaScript always moves the selection to
the start of the editable root, under 3 specific conditions:
a. The selection is collapsed.
b. The editable root (i.e. contenteditable `DIV` marked above) has ≥1 children.
c. The selection anchor (`getSelection().anchorNode`) is equal to the editable root.
Because we satisfy all three of the above conditions (since the selection anchor is at offset 1 in
the editable root), the selection is always moved to the start, which causes the bug.
This does not happen in Chrome because, upon initially creating the `BLOCKQUOTE` element, Chrome
wraps the block quote in a redundant `DIV`, such that the final selection after outdenting places
the selection anchor under this new `DIV` rather than under the root editable.
```
--- Chrome, after outdenting
<DIV contenteditable> # Editable root
<DIV>
<BLOCKQUOTE>
<DIV>
Some text
# Selection is here
<BR>
```
This also does not happen in Firefox because outdenting creates a DOM structure that has an extra
`DIV` element containing the `BR`:
```
--- Firefox, after outdenting
<DIV contenteditable> # Editable root
<BLOCKQUOTE>
<DIV>
Some text
<DIV>
# Selection is here
<BR>
```
To address this issue, this patch aligns our behavior to Firefox, by ensuring that the placeholder
`BR` above is additionally contained in the document's default paragraph element (i.e. `DIV`). This
approach is a bit less intrusive of a change than adjusting to match Chrome's behavior, but still
avoids this bug.
* LayoutTests/editing/execCommand/outdent-break-with-style-expected.txt:
* LayoutTests/editing/execCommand/outdent-regular-blockquote-expected.txt:
* LayoutTests/editing/execCommand/outdent-selection-expected.txt:
* LayoutTests/editing/execCommand/unindent-nested-blockquote-with-inner-div-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/editing/run/outdent_1-1000-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/editing/run/outdent_2001-last-expected.txt:
Rebaseline various layout tests to account for the new behavior.
* Source/WebCore/editing/IndentOutdentCommand.cpp:
(WebCore::IndentOutdentCommand::outdentParagraph):
Canonical link: https://commits.webkit.org/285745@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list