-
Notifications
You must be signed in to change notification settings - Fork 2k
Limit composer arrow-key mention jumps to adjacent mention boundaries #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,52 @@ export function expandCollapsedComposerCursor(text: string, cursorInput: number) | |
| return expandedCursor; | ||
| } | ||
|
|
||
| function collapsedSegmentLength(segment: { type: "text"; text: string } | { type: "mention" }): number { | ||
| return segment.type === "mention" ? 1 : segment.text.length; | ||
| } | ||
|
|
||
| function clampCollapsedComposerCursor( | ||
| segments: ReadonlyArray<{ type: "text"; text: string } | { type: "mention" }>, | ||
| cursorInput: number, | ||
| ): number { | ||
| const collapsedLength = segments.reduce( | ||
| (total, segment) => total + collapsedSegmentLength(segment), | ||
| 0, | ||
| ); | ||
| if (!Number.isFinite(cursorInput)) { | ||
| return collapsedLength; | ||
| } | ||
| return Math.max(0, Math.min(collapsedLength, Math.floor(cursorInput))); | ||
| } | ||
|
|
||
| export function isCollapsedCursorAdjacentToMention( | ||
| text: string, | ||
| cursorInput: number, | ||
| direction: "left" | "right", | ||
| ): boolean { | ||
| const segments = splitPromptIntoComposerSegments(text); | ||
| if (!segments.some((segment) => segment.type === "mention")) { | ||
| return false; | ||
| } | ||
|
|
||
| const cursor = clampCollapsedComposerCursor(segments, cursorInput); | ||
| let collapsedOffset = 0; | ||
|
|
||
| for (const segment of segments) { | ||
| if (segment.type === "mention") { | ||
| if (direction === "left" && cursor === collapsedOffset + 1) { | ||
| return true; | ||
| } | ||
| if (direction === "right" && cursor === collapsedOffset) { | ||
| return true; | ||
| } | ||
| } | ||
| collapsedOffset += collapsedSegmentLength(segment); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regex-based mention detection mismatches Lexical node treeMedium Severity
Additional Locations (2) |
||
|
|
||
| export function detectComposerTrigger(text: string, cursorInput: number): ComposerTrigger | null { | ||
| const cursor = clampCursor(text, cursorInput); | ||
| const lineStart = text.lastIndexOf("\n", Math.max(0, cursor - 1)) + 1; | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
components/ComposerPromptEditor.tsx:473When the user presses
Shift + ArrowLeftorShift + ArrowRightnext to a mention, theComposerMentionArrowPluginconsumes the event and moves the cursor instead of allowing Lexical to extend the selection. This makes mention nodes impossible to select via keyboard. Consider adding a check forevent?.shiftKeyand returningfalseearly when the shift modifier is held, so standard selection behavior is preserved.(event) => { + if (event?.shiftKey) return false; let nextOffset: number | null = null;🚀 Reply "fix it for me" or copy this AI Prompt for your agent: