Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Use mention adjacency helper in composer onChange
Julius Marmingea2682de4214c
diff --git a/apps/web/src/components/ComposerPromptEditor.tsx b/apps/web/src/components/ComposerPromptEditor.tsxindex 6795d0535..2c089dab0 100644--- a/apps/web/src/components/ComposerPromptEditor.tsx+++ b/apps/web/src/components/ComposerPromptEditor.tsx@@ -558,29 +558,6 @@ function ComposerMentionSelectionNormalizePlugin() {return null;}-function $isCursorAdjacentToMention(): boolean {- const selection = $getSelection();- if (!$isRangeSelection(selection) || !selection.isCollapsed()) return false;- const anchorNode = selection.anchor.getNode();-- if (anchorNode instanceof ComposerMentionNode) return true;-- if ($isElementNode(anchorNode)) {- const childIndex = selection.anchor.offset - 1;- if (childIndex >= 0) {- const child = anchorNode.getChildAtIndex(childIndex);- if (child instanceof ComposerMentionNode) return true;- }- }-- if ($isTextNode(anchorNode) && selection.anchor.offset === 0) {- const prev = anchorNode.getPreviousSibling();- if (prev instanceof ComposerMentionNode) return true;- }-- return false;-}-function ComposerMentionBackspacePlugin() {const [editor] = useLexicalComposerContext();@@ -756,7 +733,10 @@ function ComposerPromptEditorInner({value: nextValue,cursor: nextCursor,};- onChangeRef.current(nextValue, nextCursor, $isCursorAdjacentToMention());+ const cursorAdjacentToMention =+ isCollapsedCursorAdjacentToMention(nextValue, nextCursor, "left") ||+ isCollapsedCursorAdjacentToMention(nextValue, nextCursor, "right");+ onChangeRef.current(nextValue, nextCursor, cursorAdjacentToMention);});}, []);diff --git a/apps/web/src/composer-logic.test.ts b/apps/web/src/composer-logic.test.tsindex 57e044186..b9990d7fd 100644--- a/apps/web/src/composer-logic.test.ts+++ b/apps/web/src/composer-logic.test.ts@@ -85,6 +85,12 @@ describe("isCollapsedCursorAdjacentToMention", () => {expect(isCollapsedCursorAdjacentToMention("plain text", 6, "right")).toBe(false);});+ it("keeps @query typing non-adjacent while no mention pill exists", () => {+ const text = "hello @pac";+ expect(isCollapsedCursorAdjacentToMention(text, text.length, "left")).toBe(false);+ expect(isCollapsedCursorAdjacentToMention(text, text.length, "right")).toBe(false);+ });+it("detects left adjacency only when cursor is directly after a mention", () => {const text = "open @AGENTS.md next";const mentionStart = "open ".length;