The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 10:00 UTC
Use mention adjacency helper in composer onChange
- replace Lexical-node cursor adjacency check with text/cursor helper - prevent `@query` typing from being treated as mention-pill adjacent - add regression test for non-pill `@pac` input
Julius Marminge committed
Mar 5, 2026 at 10:43 UTC
a2682de4214cd277089fbf4a4c848d57a967f76d
2 files changed
+10
-24
apps/web/src/components/ComposerPromptEditor.tsx
+4
-24
@@ -558,29 +558,6 @@ function ComposerMentionSelectionNormalizePlugin() {
558
return null;
559
}
560
561
-function $isCursorAdjacentToMention(): boolean {
562
- const selection = $getSelection();
563
- if (!$isRangeSelection(selection) || !selection.isCollapsed()) return false;
564
- const anchorNode = selection.anchor.getNode();
565
-
566
- if (anchorNode instanceof ComposerMentionNode) return true;
567
-
568
- if ($isElementNode(anchorNode)) {
569
- const childIndex = selection.anchor.offset - 1;
570
- if (childIndex >= 0) {
571
- const child = anchorNode.getChildAtIndex(childIndex);
572
- if (child instanceof ComposerMentionNode) return true;
573
- }
574
- }
575
-
576
- if ($isTextNode(anchorNode) && selection.anchor.offset === 0) {
577
- const prev = anchorNode.getPreviousSibling();
578
- if (prev instanceof ComposerMentionNode) return true;
579
- }
580
-
581
- return false;
582
-}
583
-
561
function ComposerMentionBackspacePlugin() {
562
const [editor] = useLexicalComposerContext();
563
@@ -756,7 +733,10 @@ function ComposerPromptEditorInner({
733
value: nextValue,
734
cursor: nextCursor,
735
};
759
- onChangeRef.current(nextValue, nextCursor, $isCursorAdjacentToMention());
736
+ const cursorAdjacentToMention =
737
+ isCollapsedCursorAdjacentToMention(nextValue, nextCursor, "left") ||
738
+ isCollapsedCursorAdjacentToMention(nextValue, nextCursor, "right");
739
+ onChangeRef.current(nextValue, nextCursor, cursorAdjacentToMention);
740
});
741
}, []);
742
apps/web/src/composer-logic.test.ts
+6
@@ -85,6 +85,12 @@ describe("isCollapsedCursorAdjacentToMention", () => {
85
expect(isCollapsedCursorAdjacentToMention("plain text", 6, "right")).toBe(false);
86
});
87
88
+ it("keeps @query typing non-adjacent while no mention pill exists", () => {
89
+ const text = "hello @pac";
90
+ expect(isCollapsedCursorAdjacentToMention(text, text.length, "left")).toBe(false);
91
+ expect(isCollapsedCursorAdjacentToMention(text, text.length, "right")).toBe(false);
92
+ });
93
+
94
it("detects left adjacency only when cursor is directly after a mention", () => {
95
const text = "open @AGENTS.md next";
96
const mentionStart = "open ".length;