Title: [295441] trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Revision
295441
Author
[email protected]
Date
2022-06-09 17:14:26 -0700 (Thu, 09 Jun 2022)

Log Message

[ iOS Debug ] ASSERTION FAILED: Attempt to access post layout data before receiving it on editing/editable-region/fixed-and-absolute-contenteditable-scrolled.html
https://bugs.webkit.org/show_bug.cgi?id=237541
rdar://89918871

Reviewed by Simon Fraser.

After the changes in r289876, this test started sometimes hitting an assertion when run immediately
after `editing/deleting/ios/backspace-last-character.html`. By eliminating a sync IPC call to the
web content process when requesting autocorrection information, UIKit now requests selection-caret-
relative character information slightly earlier than it previously did when dismissing the keyboard,
which may occur after we've received an editor state update after blurring the focused element, but
before we've received post-layout data.

In this scenario, we already know that the focused element has been blurred and the selection is no
longer editable, so once the post-layout data does arrive, it would contain `0` for all of the
characters close to the selection caret.

As such, we can simply return 0 early before attempting to access post-layout data if the selection
is not a caret in editable content, since all of the relevant post-layout data members
(`characterAfterSelection`, `characterBeforeSelection` and `twoCharacterBeforeSelection`) are going
to be 0 anyways.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _characterInRelationToCaretSelection:]):

Canonical link: https://commits.webkit.org/251447@main

Modified Paths

Diff

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (295440 => 295441)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-06-09 23:43:51 UTC (rev 295440)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-06-10 00:14:26 UTC (rev 295441)
@@ -4869,20 +4869,22 @@
     });
 }
 
-- (UTF32Char)_characterBeforeCaretSelection
+- (UTF32Char)_characterInRelationToCaretSelection:(int)amount
 {
-    return _lastInsertedCharacterToOverrideCharacterBeforeSelection.value_or(_page->editorState().postLayoutData().characterBeforeSelection);
-}
+    if (amount == -1 && _lastInsertedCharacterToOverrideCharacterBeforeSelection)
+        return *_lastInsertedCharacterToOverrideCharacterBeforeSelection;
 
-- (UTF32Char)_characterInRelationToCaretSelection:(int)amount
-{
+    auto& state = _page->editorState();
+    if (!state.isContentEditable || state.selectionIsNone || state.selectionIsRange)
+        return 0;
+
     switch (amount) {
     case 0:
-        return _page->editorState().postLayoutData().characterAfterSelection;
+        return state.postLayoutData().characterAfterSelection;
     case -1:
-        return self._characterBeforeCaretSelection;
+        return state.postLayoutData().characterBeforeSelection;
     case -2:
-        return _page->editorState().postLayoutData().twoCharacterBeforeSelection;
+        return state.postLayoutData().twoCharacterBeforeSelection;
     default:
         return 0;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to