Skip to content

Improve handling of navigation keys in typing state#2644

Merged
bengotow merged 1 commit intoFoundry376:masterfrom
ejbiker93ss:master
Mar 18, 2026
Merged

Improve handling of navigation keys in typing state#2644
bengotow merged 1 commit intoFoundry376:masterfrom
ejbiker93ss:master

Conversation

@ejbiker93ss
Copy link
Copy Markdown

Refactor typing state management to handle navigation keys correctly.

Refactor typing state management to handle navigation keys correctly.
@indent-staging
Copy link
Copy Markdown
Contributor

indent-staging Bot commented Mar 18, 2026

Issues

1 potential issue found:

  • Autofix Modifier-only keypresses (Shift, Ctrl, Alt, Meta) are not in the navigation key list, so pressing a modifier alone after 800ms idle will trigger the isTyping state and toggle spellcheck, potentially causing the same cursor-reset issue this PR aims to fix. This is a minor edge case since modifier-only keydowns are uncommon in isolation.

Summary

This PR fixes a UX bug where pressing navigation keys (Home, End, arrow keys, PageUp, PageDown) in the composer editor after 800ms of typing inactivity would cause the keypress to be "swallowed." The root cause was that toggling the spellCheck attribute on a contenteditable element causes Chromium to reset the cursor/selection, and navigation keys were incorrectly triggering this toggle.

  • Navigation keys are now excluded from triggering the isTyping state transition, preventing unnecessary spellcheck attribute toggling
  • Navigation keys no longer reset the 800ms debounce timer (_onDoneTyping), so they don't extend the typing window
  • The next() call still executes unconditionally, ensuring Slate's default key handling is always invoked

CI Checks

Waiting for CI checks...

Rule Checks 3 rules evaluated, 3 passed, 0 failed

Passing rules

Passing This is a longer title to see what happens when they are too long to fit
Passing B
Passing Ben Rule

Autofix All

@ejbiker93ss
Copy link
Copy Markdown
Author

Tested and working on my machine 😉

// first Home/End press after 800ms of inactivity would be "eaten" by the spellCheck
// re-render. We skip the isTyping transition for these keys to avoid that.
const isNavigationKey = [
'Home', 'End', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Modifier-only keys not excluded: Pressing Shift, Ctrl, Alt, or Meta alone doesn't produce text but will still trigger the isTyping transition and spellcheck toggle. Consider adding 'Shift', 'Control', 'Alt', 'Meta' to this list (and possibly renaming it to isNonTypingKey) to avoid the same cursor-reset issue for these keys. The practical impact is small since standalone modifier presses are uncommon, but it would make the fix more complete.

Copy link
Copy Markdown
Collaborator

@bengotow bengotow left a comment

Choose a reason for hiding this comment

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

This looks great, this was definitely an oversight when we switched to this approach. Thanks!

@bengotow bengotow merged commit 7dbeba6 into Foundry376:master Mar 18, 2026
1 check passed
@ejbiker93ss
Copy link
Copy Markdown
Author

@bengotow , thank you for the quick action here!

@foundry376-bot
Copy link
Copy Markdown

This pull request has been mentioned on Mailspring Community. There might be relevant details there:

https://community.getmailspring.com/t/cant-go-to-start-end-of-the-line-with-home-end-keys/14291/3

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.

3 participants