[webkit-changes] [WebKit/WebKit] b4d744: REGRESSION (277282 at main): [macOS] Writing suggesti...
Wenson Hsieh
noreply at github.com
Fri Apr 19 13:34:24 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: b4d7445ce5f49f51d491b03d64e83a235949a28b
https://github.com/WebKit/WebKit/commit/b4d7445ce5f49f51d491b03d64e83a235949a28b
Author: Wenson Hsieh <wenson_hsieh at apple.com>
Date: 2024-04-19 (Fri, 19 Apr 2024)
Changed paths:
M LayoutTests/TestExpectations
A LayoutTests/editing/input/mac/show-inline-prediction-with-adjacent-text-expected-mismatch.html
A LayoutTests/editing/input/mac/show-inline-prediction-with-adjacent-text.html
M LayoutTests/platform/mac-wk2/TestExpectations
M LayoutTests/resources/ui-helper.js
M Source/WebCore/editing/Editor.cpp
M Source/WebCore/editing/Editor.h
M Source/WebCore/rendering/updating/RenderTreeUpdaterGeneratedContent.cpp
M Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
M Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
M Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h
M Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
M Tools/WebKitTestRunner/mac/UIScriptControllerMac.h
M Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm
Log Message:
-----------
REGRESSION (277282 at main): [macOS] Writing suggestions may incorrectly render at the end of an editable element
https://bugs.webkit.org/show_bug.cgi?id=272898
rdar://126493252
Reviewed by Richard Robinson.
After the changes in 277282 at main, inline writing suggestions use generated `RenderText` to render
the suggested text content after the current selection. To identify where to insert this generated
renderer, we currently walk up from the caret selection's container node until we encounter an
`Element`; this element's renderer then acts as the parent for this generated text renderer.
While this seems to work in most cases, it fails in the scenario where a single element contains
multiple text nodes underneath it, and the user is typing before a newline. Since we're only capable
of inserting the generated content at the end of an element renderer, it appears in the wrong place
(at the end of the contaiing element), rather than where the user is actually typing.
```
DIV // parent element
"Foo" // user is typing here
"\n" // newline
"Bar" // writing suggestion renderer is inserted here
```
To fix this, we refactor some of this logic around managing the writing suggestions renderer:
1. Instead of trying to keep track of the containing element enclosing the writing suggestions,
just keep track of the node *before which* we expect writing suggestions to be inserted.
Importantly, this is robust in the case described above, where we return `"Foo"` instead of the
element containing all three nodes.
2. When updating the render tree to add generated content for writing suggestions, use the optional
`beforeChild` argument of `RenderTreeBuilder::attach` to ensure that the writing suggestions
renderer is inserted in the right place, relative to the renderer of the node found in (1).
Test: editing/input/mac/show-inline-prediction-with-adjacent-text.html
* LayoutTests/TestExpectations:
* LayoutTests/editing/input/mac/show-inline-prediction-with-adjacent-text-expected-mismatch.html: Added.
* LayoutTests/editing/input/mac/show-inline-prediction-with-adjacent-text.html: Added.
Add a layout test to exercise the fix by verifying that the writing suggestion is not rendered at
the end of the editable container, in the case where the suggested text is being inserted before the
newline.
* LayoutTests/platform/mac-wk2/TestExpectations:
* LayoutTests/resources/ui-helper.js:
(window.UIHelper.async setInlinePrediction):
Augment an existing testing hook to insert inline predictions, so that it works on macOS as well.
To facilitate this, we introduce a second parameter (optional on iOS) to indicating the start index
of the predicted text, relative to the full text. This defaults to 0, which simply inserts the
inline prediction at the caret position (regardless of whether the text before the caret matches the
expected text).
* Source/WebCore/editing/Editor.cpp:
(WebCore::Editor::nodeBeforeWritingSuggestions const):
(WebCore::Editor::writingSuggestionsContainerElement const):
Reimplement this in terms of `nodeBeforeWritingSuggestions`; see above for more details.
(WebCore::Editor::removeWritingSuggestionIfNeeded):
(WebCore::Editor::setWritingSuggestion):
(WebCore::Editor::writingSuggestionsContainerElement): Deleted.
* Source/WebCore/editing/Editor.h:
* Source/WebCore/rendering/updating/RenderTreeUpdaterGeneratedContent.cpp:
(WebCore::RenderTreeUpdater::GeneratedContent::updateWritingSuggestionsRenderer):
See comments above for more details. Drive-by fix: also avoid adding extra renderers for empty text
nodes, in the case where there is no suffix text.
* Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
Add test support for simulating inline predictions (writing suggestions) on macOS. See above.
* Tools/TestRunnerShared/UIScriptContext/UIScriptController.h:
(WTR::UIScriptController::setInlinePrediction):
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.h:
* Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::setInlinePrediction):
* Tools/WebKitTestRunner/mac/UIScriptControllerMac.h:
* Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::setInlinePrediction):
Canonical link: https://commits.webkit.org/277756@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