fix: composer @file autocomplete cursor and spacing bugs#936
fix: composer @file autocomplete cursor and spacing bugs#936chuks-qua wants to merge 2 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
7e6ae59 to
a47a5fe
Compare
|
authorization is needed for redeployment |
a47a5fe to
5605fa1
Compare
fdbe241 to
8f3b32a
Compare
|
Hi, thanks for looking into the issue I filed for #291 . I took a brief look as of 8f3b32a the likely remaining items I have are:
|
Hey, thanks for pointing this out, i am looking into it now. EditLooked into it and now i follow what you are saying. Note used Cursor after insertion I am implementing the fixes. |
9918194 to
eee6cf7
Compare
…utocomplete expandCollapsedComposerCursor uses a regex to find mentions in raw text, which false-matches plain text like @in when the user types @ before an existing word. This corrupts the cursor mapping and prevents trigger detection from firing. Compute the expanded cursor directly from the Lexical editor's node tree, which knows which nodes are actual ComposerMentionNode instances. Pass this expanded cursor through onChange and readSnapshot so detectComposerTrigger receives the correct text offset. Closes pingdotgg#291 Related to pingdotgg#922
2cd327f to
28a40d7
Compare
…ailing space applyPromptReplacement stored the expanded cursor from replaceTextRange as a collapsed cursor, causing the caret to jump to the end of the line after selecting a completion when a mention pill existed earlier in the prompt. Convert the cursor with collapseExpandedComposerCursor before storing and restoring focus. When a replacement already ends with a space and the character at the cursor is also a space, extend the replacement range to consume the existing space so the result has exactly one. Fix all other setComposerCursor call sites that passed expanded offsets where collapsed offsets were expected.
Closes #291
Closes #922
What Changed
Three fixes for the composer's
@fileautocomplete.Mid-text
@trigger detection:ComposerPromptEditornow computes an expanded cursor from the Lexical node tree and passes it throughonChangeandreadSnapshot.ChatViewuses this expanded cursor indetectComposerTriggerinstead of the regex-basedexpandCollapsedComposerCursor.Double space after completion:
When the replacement (
@AGENTS.md) already ends with a space and a space exists at the cursor, the insertion now consumes the existing space instead of leaving two.Caret lands at end of line after completion:
applyPromptReplacementreturned an expanded cursor fromreplaceTextRangebut stored it as a collapsed cursor. AllsetComposerCursorcall sites now use the correct coordinate system.Code changes:
getExpandedAbsoluteOffsetForPointand$readExpandedSelectionOffsetFromEditorStatetoComposerPromptEditor.tsxexpandedCursorthrough theonChangecallback andreadSnapshotinterfacecollapseExpandedComposerCursorand exportclampCollapsedComposerCursorincomposer-logic.tsextendReplacementRangeForTrailingSpaceto consume trailing spaces during completionsetComposerCursorcall sites to store collapsed offsetsWhy
expandCollapsedComposerCursorusesMENTION_TOKEN_REGEXto locate mentions in raw text. When a user types@before an existing word (e.g., cursor betweeninspectandin this sentence), the regex matches@inas a mention and shifts the cursor past it.detectComposerTriggerthen receives the wrong offset and returns null, so the autocomplete popup never appears.The Lexical editor already tracks which nodes are
ComposerMentionNodeinstances. Reading the expanded cursor directly from the node tree eliminates the regex false-match problem.The other two bugs come from mixing collapsed and expanded cursor offsets in
ChatViewandComposerPromptEditor. Collapsed offsets count a mention pill as 1 character; expanded offsets count by full text length (@AGENTS.md= 11). Passing an expanded offset where collapsed is expected inflates the cursor position, and failing to consume an existing trailing space doubles the gap.UI Changes
Before
composer-before-fix.mp4
After
compose-after-fix.mp4
Checklist
Note
Fix
@fileautocomplete trigger detection when cursor is mid-prompt with trailing textcollapseExpandedComposerCursorandclampCollapsedComposerCursorexports to composer-logic.ts to convert between cursor representations.onChangesignature andreadSnapshotreturn value.extendReplacementRangeForTrailingSpacein ChatView.tsx so inserting a path or/modeltoken that ends with a space consumes any existing trailing space at the insertion point, preventing double spaces.Macroscope summarized 28a40d7.