Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 18268bbc067da5473c03a0896409d1ba1b71f8e0
https://github.com/WebKit/WebKit/commit/18268bbc067da5473c03a0896409d1ba1b71f8e0
Author: Wenson Hsieh <[email protected]>
Date: 2024-10-13 (Sun, 13 Oct 2024)
Changed paths:
A
LayoutTests/editing/input/cocoa/inline-predictions-in-text-with-leading-whitespace-expected.html
A
LayoutTests/editing/input/cocoa/inline-predictions-in-text-with-leading-whitespace.html
M Source/WebCore/editing/Editor.cpp
Log Message:
-----------
Writing suggestions show in the wrong place when the text node contains
leading non-visible whitespace
https://bugs.webkit.org/show_bug.cgi?id=281403
rdar://137237226
Reviewed by Richard Robinson.
In the case where writing suggestions are inserted within a text node with
leading whitespace, we
end up inserting the generated renderer (representing the suggested text) at
the wrong offset within
the text node.
This happens because `WritingSuggestionData::offset()` is incorrect when we set
up the suggested
text renderer in
`RenderTreeUpdater::GeneratedContent::updateWritingSuggestionsRenderer`. This
offset is in turn computed in `Editor::setWritingSuggestion`, where we use
`characterCount` to get
the number of characters between the start of the text node and the caret
position. The problem with
this approach is that `characterCount` ignores non-rendered whitespace, but the
result is then used
to index into the text node's data, which includes non-rendered whitespace,
when determining whether
(or how) to split up the existing text node to insert writing suggestions. As a
result, the writing
suggestions renderer is incorrectly offset by an amount equal to the number of
non-rendered
whitespace characters at the start of the text node.
To fix this, we use the `endOffset()` of the selection range, after verifying
that the selection
range is both (1) collapsed, and (2) an offset within a text node. The current
implementation of
writing suggestions doesn't work properly unless these conditions are met
anyways, so it's safe to
enforce this and simply use the end offset relative to the containing text.
*
LayoutTests/editing/input/cocoa/inline-predictions-in-text-with-leading-whitespace-expected.html:
Added.
*
LayoutTests/editing/input/cocoa/inline-predictions-in-text-with-leading-whitespace.html:
Added.
Add a layout test to exercise the change, by verifying that inserting a writing
suggestion after the
end of `<div contenteditable>To </div>` results in the same behavior as
inserting the same
suggestion after the end of `<div contenteditable> To </div>`.
* Source/WebCore/editing/Editor.cpp:
(WebCore::Editor::setWritingSuggestion):
Canonical link: https://commits.webkit.org/285107@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes