Skip to content

Fix prompt keyboard navigation inside tables#718

Merged
jorgemanrubia merged 5 commits intobasecamp:mainfrom
yanfroes:fix-keyboard-navigation-table
Mar 3, 2026
Merged

Fix prompt keyboard navigation inside tables#718
jorgemanrubia merged 5 commits intobasecamp:mainfrom
yanfroes:fix-keyboard-navigation-table

Conversation

@yanfroes
Copy link
Contributor

@yanfroes yanfroes commented Feb 4, 2026

Fixes #677

Problem
When using @ mentions (or other prompts) inside a table cell, pressing arrow keys navigates between table cells instead of navigating the dropdown options.

Cause
Lexical's table plugin registers arrow key handlers at COMMAND_PRIORITY_HIGH during editor initialization. The prompt also registered its handlers at the same priority, but later—causing table handlers to intercept keyboard events first.

Solution
Changed prompt key handlers from COMMAND_PRIORITY_HIGH to COMMAND_PRIORITY_CRITICAL, ensuring they take precedence over table navigation when the prompt is open.

lexxy-fix-prompt-keyboard-navigation-inside-tables.mp4

Copilot AI review requested due to automatic review settings February 4, 2026 22:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes keyboard navigation for prompt dropdowns (e.g., @ mentions) when used inside table cells by changing the priority of keyboard event handlers from COMMAND_PRIORITY_HIGH to COMMAND_PRIORITY_CRITICAL.

Changes:

  • Updated keyboard command registration priorities in prompt.js from COMMAND_PRIORITY_HIGH to COMMAND_PRIORITY_CRITICAL for all key handlers (ENTER, TAB, SPACE, ARROW_UP, ARROW_DOWN)
  • Imported COMMAND_PRIORITY_CRITICAL from Lexical
  • Updated comments to reflect the new priority level

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zoltanhosszu
Copy link
Contributor

I like this, a simple solution, thank you @yanfroes!

@samuelpecher any feedback on this?

Copy link
Collaborator

@samuelpecher samuelpecher left a comment

Choose a reason for hiding this comment

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

LGTM; I wouldn't want to push the table handle commands down the priority list, so 👍

Copy link
Collaborator

@samuelpecher samuelpecher left a comment

Choose a reason for hiding this comment

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

This could do with a test to ensure we don't regress in the future if priorities are ever revised.

@yanfroes yanfroes requested a review from samuelpecher February 9, 2026 22:06
@yanfroes
Copy link
Contributor Author

yanfroes commented Feb 9, 2026

@zoltanhosszu @samuelpecher Just added the test! =)

Copy link
Contributor

@zoltanhosszu zoltanhosszu left a comment

Choose a reason for hiding this comment

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

Looking solid! Let's ship it :) 🚀

@yanfroes yanfroes force-pushed the fix-keyboard-navigation-table branch from beec132 to 72a36d5 Compare February 25, 2026 12:01
yanfroes and others added 4 commits March 3, 2026 12:57
When a prompt (e.g., @ mentions) is open inside a table cell, arrow keys
should navigate the dropdown options, not the table cells.

Changed prompt key handlers from COMMAND_PRIORITY_HIGH to
COMMAND_PRIORITY_CRITICAL so they run before table navigation handlers.

Fixes basecamp#677
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds regression test for basecamp#677 to ensure arrow keys navigate prompt items when the prompt is opened inside a table cell. Verifies that prompt key handlers maintain COMMAND_PRIORITY_CRITICAL to prevent the table plugin from intercepting arrow key events.
Copilot AI review requested due to automatic review settings March 3, 2026 11:58
@jorgemanrubia jorgemanrubia force-pushed the fix-keyboard-navigation-table branch from 72a36d5 to ae248d3 Compare March 3, 2026 11:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 9 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

test/system/prompts_test.rb:114

  • The assertions immediately after find_editor.send :arrow_down may be flaky because send_keys doesn’t flush Lexical updates, and the DOM/aria-selected state may not be updated by the time we re-query .lexxy-prompt-menu__item. Consider wrapping the post-keypress assertions in wait_until (e.g., wait until the second item becomes selected and the prompt is still open) so flush_lexical_updates runs before asserting.
    find_editor.send :arrow_down

    assert find_editor.open_prompt?, "Prompt closed after pressing arrow down. The table plugin intercepted the key event because prompt handlers are not using COMMAND_PRIORITY_CRITICAL."

    prompt_items = all(".lexxy-prompt-menu__item")
    refute prompt_items[0]["aria-selected"], "First item should not be selected after arrow down"
    assert prompt_items[1]["aria-selected"], "Second item should be selected after arrow down - prompt handled the arrow key"

test/system/prompts_test.rb:122

  • Same as above for the :arrow_up path: after find_editor.send :arrow_up, the selection/aria-selected changes may not be reflected immediately across drivers/CI timing. Wrapping the re-query + assertions in wait_until (waiting for the first item to regain selection) will make this system test more reliable.
    find_editor.send :arrow_up

    assert find_editor.open_prompt?, "Prompt should remain open after arrow up"

    prompt_items = all(".lexxy-prompt-menu__item")
    assert prompt_items[0]["aria-selected"], "First item should be selected after arrow up"
    refute prompt_items[1]["aria-selected"], "Second item should not be selected after arrow up"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jorgemanrubia jorgemanrubia merged commit c4c3ff0 into basecamp:main Mar 3, 2026
2 checks passed
mbarta pushed a commit that referenced this pull request Mar 4, 2026
* origin/main: (77 commits)
  Version 0.8.0.beta
  Fix prompt keyboard navigation inside tables (#718)
  Bump turbo-rails to 2.0.23 and importmap-rails to 2.2.3 (#773)
  Build assets
  Add upload lifecycle events (upload-start, upload-progress, upload-end)
  Build assets
  Fix non-advancing caret
  Explicitely return false in Paste handler
  Make attachment image undraggable
  Test gallery ActionText rendering
  Handle `null` selection for isOnPreviewableImage
  Prevent crash on missing `img[src]`
  Fix pasting remove images bug
  Clarifying rename
  Add cursor-based gallery tests
  Allow DOM selection update when promoting an attachment upload
  Remove async from upload promotion function
  selectEnd of the last uploaded node, not the node itself
  Remove an empty element before a DecoratorNode on Delete/Backspace
  refactor `contents.insertAtCursor`
  ...

# Conflicts:
#	app/assets/javascript/lexxy.js
#	app/assets/javascript/lexxy.js.br
#	app/assets/javascript/lexxy.js.gz
#	app/assets/javascript/lexxy.min.js
#	app/assets/javascript/lexxy.min.js.br
#	app/assets/javascript/lexxy.min.js.gz
#	src/nodes/action_text_attachment_upload_node.js
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.

Prompts keyboard controls are broken in tables

5 participants