Skip to content

Dismiss caret on Android when the virtual keyboard is closed without blur#4444

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-caret-dismissal-issue
Open

Dismiss caret on Android when the virtual keyboard is closed without blur#4444
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-caret-dismissal-issue

Conversation

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

On Android, dismissing the virtual keyboard with the Down Arrow button hides the keyboard without blurring the editable, so no blur event fires and the caret keeps blinking on the thought.

Root cause

src/util/handleKeyboardVisibility.ts already detects the keyboard closing from a visualViewport resize and exits edit mode (clears the selection, sets isKeyboardOpen: false), but it was never attached to any listener — effectively dead code. The only resize listener wired (updateSize) does not touch the caret, and Android has no active virtual-keyboard handler (iOSSafariHandler early-returns when not Safari).

Changes

  • src/util/initEvents.ts — wire handleKeyboardVisibility to the resize event alongside the existing updateSize listener, with matching teardown in cleanup.

    const resizeHost = window.visualViewport || window
    resizeHost.addEventListener('resize', updateSize)
    // On Android, dismissing the virtual keyboard (e.g. via the Down Arrow button) hides the keyboard
    // without blurring the editable, so no blur event fires to dismiss the caret. Detect the keyboard
    // closing from the viewport resize and exit edit mode.
    resizeHost.addEventListener('resize', handleKeyboardVisibility)
  • src/e2e/puppeteer/__tests__/caret.ts — regression test in the mobile only block simulating a keyboard-open then Down-Arrow dismiss (viewport resize without blur), asserting the selection is cleared.

Cross-platform safety

The handler is touch-gated (no-op on desktop), throttled, only acts when isKeyboardOpen && cursor, and ignores rotation (currentWidth === lastViewportWidth). On iOS the keyboard close fires blur first (Editable.tsx dispatches keyboardOpen({ value: false })), so the resize handler runs as a no-op there.

Copilot AI and others added 3 commits June 24, 2026 06:12
…ndroid keyboard Down Arrow (#3958)

Co-authored-by: BayuAri <8419585+BayuAri@users.noreply.github.com>
…ndroid keyboard Down Arrow (#3958)

Co-authored-by: BayuAri <8419585+BayuAri@users.noreply.github.com>
#3958)

Co-authored-by: BayuAri <8419585+BayuAri@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix caret not dismissed with down arrow keyboard action Dismiss caret on Android when the virtual keyboard is closed without blur Jun 24, 2026
Copilot AI requested a review from BayuAri June 24, 2026 06:26
…3958)

The Capacitor Android app does not resize the WebView when the keyboard
opens/closes (windowSoftInputMode=adjustNothing + IME inset stripping in
MainActivity, mirroring iOS Keyboard resize:'none'), so the visualViewport
resize event never fires and the previous resize-based handler never ran on
the device. Dismissing the keyboard via the Down Arrow nav-bar button also
does not blur the editable, so no blur event dismisses the caret.

Add an Android Capacitor virtual-keyboard handler that listens to the native
keyboardDidHide event and clears the caret / exits edit mode. Extract the
shared dismissCaretOnKeyboardClose helper, reused by the existing resize
handler (which still covers Android mobile web/PWA where the viewport resizes).

Add a unit test mocking @capacitor/keyboard to cover the new handler, since the
native path cannot be exercised by Puppeteer.

@BayuAri BayuAri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm fixed.
Caret is auto dismissed along with keyboard when closed from down arrow on the nav bar.

@BayuAri BayuAri marked this pull request as ready for review June 24, 2026 07:40
@BayuAri BayuAri requested a review from raineorshine June 24, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Caret is not dismissed when user dismisses keyboard by Down Arrow on the Android Virtual button

2 participants