Skip to content
Permalink
Browse files
[iOS 16] Previously dictated input is inserted in next field when cha…
…nging focused element

https://bugs.webkit.org/show_bug.cgi?id=241751
rdar://84995538

Reviewed by Megan Gardner.

When changing focus between text fields while continuous dictation is active, dictated text in the
previously focused text field is inserted in the newly focused field. This happens because UIKit
attempts to update the dictation string one final time prior to changing the keyboard input
delegate; however, this doesn't work in `WKWebView`, due to the fact that the previous field has
already been blurred by the time we handle element focus and reload input views in the UI process.

Mitigate this by treating `-replaceDictatedText:withText:` and `-insertText:` as no-ops in the case
where they are triggered while hiding the keyboard; note that this only changes behavior in cases
where UIKit would've otherwise inserted or modified text in newly focused elements, while only
having text input and autocorrection context from the previously focused element -- as such, it's
very unlikely that any (intended) platform editing behaviors in WebKit2 depend on the ability to
insert text in this specific scenario.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:

Add a new `_isHidingKeyboard` flag.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView replaceDictatedText:withText:]):
(-[WKContentView insertText:]):
(-[WKContentView _hideKeyboard]):

Set `_isHidingKeyboard` during the scope of this method call.

Canonical link: https://commits.webkit.org/251694@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Jun 21, 2022
1 parent 5a29003 commit 95368efc6e4a19001d0bea172219236ec18241f3
Showing 2 changed files with 9 additions and 0 deletions.
@@ -464,6 +464,7 @@ using ImageAnalysisRequestIdentifier = ObjectIdentifier<ImageAnalysisRequestIden
BOOL _isUnsuppressingSoftwareKeyboardUsingLastAutocorrectionContext;
BOOL _waitingForKeyboardToStartAnimatingInAfterElementFocus;
BOOL _shouldZoomToFocusRectAfterShowingKeyboard;
BOOL _isHidingKeyboard;

BOOL _focusRequiresStrongPasswordAssistance;
BOOL _waitingForEditDragSnapshot;
@@ -4927,6 +4927,9 @@ - (void)didInsertFinalDictationResult

- (void)replaceDictatedText:(NSString*)oldText withText:(NSString *)newText
{
if (_isHidingKeyboard && _isChangingFocus)
return;

_autocorrectionContextNeedsUpdate = YES;
_page->replaceDictatedText(oldText, newText);
}
@@ -5657,6 +5660,9 @@ - (BOOL)_shouldSimulateKeyboardInputOnTextInsertion
// Inserts the given string, replacing any selected or marked text.
- (void)insertText:(NSString *)aStringValue
{
if (_isHidingKeyboard && _isChangingFocus)
return;

auto* keyboard = [UIKeyboardImpl sharedInstance];

WebKit::InsertTextOptions options;
@@ -6605,6 +6611,8 @@ - (void)_showKeyboard

- (void)_hideKeyboard
{
SetForScope isHidingKeyboardScope { _isHidingKeyboard, YES };

self.inputDelegate = nil;
[self setUpTextSelectionAssistant];

0 comments on commit 95368ef

Please sign in to comment.