Skip to content

Guard SlashMenu navigation against empty filtered items#19

Merged
akshad-exe merged 2 commits into
feature/tiptapfrom
copilot/sub-pr-17-again
Feb 9, 2026
Merged

Guard SlashMenu navigation against empty filtered items#19
akshad-exe merged 2 commits into
feature/tiptapfrom
copilot/sub-pr-17-again

Conversation

Copilot AI commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Arrow key navigation in SlashMenu breaks when filtering returns zero items. Modulo operations like (prev + 1) % 0 yield NaN, poisoning selectedIndex and breaking all subsequent navigation.

Changes:

  • Guard ArrowDown/ArrowUp handlers: skip index update when filteredItems.length === 0
  • Guard Enter handler: prevent selection when no items exist
// Before: NaN poisons selectedIndex when filteredItems is empty
setSelectedIndex((prev) => (prev + 1) % filteredItems.length);

// After: navigation no-ops safely when no items
if (filteredItems.length > 0) {
  setSelectedIndex((prev) => (prev + 1) % filteredItems.length);
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Address feedback from review on Feature/tiptap PR Guard SlashMenu navigation against empty filtered items Feb 9, 2026
Copilot AI requested a review from akshad-exe February 9, 2026 02:29
@akshad-exe akshad-exe marked this pull request as ready for review February 9, 2026 02:32
Copilot AI review requested due to automatic review settings February 9, 2026 02:32
@akshad-exe akshad-exe merged commit 4923815 into feature/tiptap Feb 9, 2026

Copilot AI left a comment

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.

Pull request overview

Fixes a keyboard-navigation edge case in the editor SlashMenu where filtering down to zero items could cause modulo-by-zero (% 0) and set selectedIndex to NaN, breaking subsequent navigation.

Changes:

  • Guard ArrowDown/ArrowUp selection updates when filteredItems.length === 0.
  • Guard Enter selection to avoid selecting when there are no filtered items.

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

Comment thread editor/ui/SlashMenu.tsx
Comment on lines 97 to +101
if (e.key === 'ArrowDown') {
e.preventDefault();
setSelectedIndex((prev) => (prev + 1) % filteredItems.length);
if (filteredItems.length > 0) {
setSelectedIndex((prev) => (prev + 1) % filteredItems.length);
}

Copilot AI Feb 9, 2026

Copy link

Choose a reason for hiding this comment

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

Consider adding an e2e regression test for this empty-results navigation case (e.g., type a slash query that yields 0 suggestions, press ArrowDown/ArrowUp/Enter, then continue typing/backspacing and verify the editor remains responsive and subsequent navigation works). The repo already has Playwright coverage for slash-menu keyboard navigation, but it doesn’t currently exercise the 0-items path that previously produced NaN.

Copilot uses AI. Check for mistakes.
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