Skip to content

fix: keep the editor typable after clicking a highlighted lint - #3834

Open
mvanhorn wants to merge 1 commit into
Automattic:masterfrom
mvanhorn:fix/3721-cant-type-after-clicking-highlight
Open

fix: keep the editor typable after clicking a highlighted lint#3834
mvanhorn wants to merge 1 commit into
Automattic:masterfrom
mvanhorn:fix/3721-cant-type-after-clicking-highlight

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Issues

Fixes #3721

Description

Root cause: in SuggestionBox.ts the FocusHook attached to the first suggestion button calls node.focus() on every popup open, moving keyboard focus off the editor and onto a <button> (which cannot accept typed text). Escape works because CloseOnEscapeHook closes the popup and restores the saved cursor. The fix is to only auto-focus a suggestion when the popup was opened via the keyboard activation key (double-tap shift/control -> openClosestToCaret), and NOT when it was opened by a pointer click (onPointerDown). PopupHandler will track which path opened the popup and thread an autofocusSuggestion flag through render() -> SuggestionBox() -> suggestions(), so the FocusHook is only wired for keyboard-opened popups. Because the highlight render box uses pointer-events: none, a click lands in the underlying editor element (the pointerdown listener source), so leaving focus there keeps the caret positioned where the user clicked and Delete/typing work immediately, while keyboard-opened popups retain focus for arrow/enter navigation and Escape still restores the cursor.

Demo

N/A - behavioral fix; validated by the tests below.

How Has This Been Tested?

  • Happy path: type a misspelled word into a textarea, wait for the red highlight, click the highlight to open the popup, press Delete (or type a character), and assert the textarea value changed and the editor retained focus (document.activeElement is the textarea).
  • Popup still usable by mouse: clicking a suggestion button in the click-opened popup still applies the replacement and closes the popup.
  • Keyboard-opened popup unchanged: opening via the activation key still focuses the first suggestion so arrow/enter navigation works, and Escape still closes and restores the caret.
  • Edge case: clicking a highlight then clicking elsewhere (outside any box) dismisses the popup without leaving focus trapped.

AI Disclosure

  • I am a human and didn't use any AI.
  • I used LLM features of my editor, but not an agent.
  • I used an AI agent interactively.
  • I am an agent or I got an agent to do the work autonomously.

Checklist

  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • I have considered splitting this into smaller pull requests.

@hippietrail hippietrail added chrome-extension Related to the Harper Chrome extension firefox-plugin Related to the Harper Firefox plugin labels Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chrome-extension Related to the Harper Chrome extension firefox-plugin Related to the Harper Firefox plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't type after clicking on the highlighted word

2 participants