Skip to content
Permalink
Browse files
[ iOS Debug ] ASSERTION FAILED: Attempt to access post layout data be…
…fore 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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295441 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Jun 10, 2022
1 parent f07f779 commit 25d5f455dc38b3892ee40edbe2c3c9e143c04013
Showing 1 changed file with 10 additions and 8 deletions.
@@ -4869,20 +4869,22 @@ - (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranul
});
}

- (UTF32Char)_characterBeforeCaretSelection
{
return _lastInsertedCharacterToOverrideCharacterBeforeSelection.value_or(_page->editorState().postLayoutData().characterBeforeSelection);
}

- (UTF32Char)_characterInRelationToCaretSelection:(int)amount
{
if (amount == -1 && _lastInsertedCharacterToOverrideCharacterBeforeSelection)
return *_lastInsertedCharacterToOverrideCharacterBeforeSelection;

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;
}

0 comments on commit 25d5f45

Please sign in to comment.