Skip to content

Commit 05dbf05

Browse files
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
1 parent b23f4d1 commit 05dbf05

2 files changed

Lines changed: 10 additions & 24 deletions

File tree

‎apps/web/src/components/ComposerPromptEditor.tsx‎

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -558,29 +558,6 @@ function ComposerMentionSelectionNormalizePlugin() {
558558
return null;
559559
}
560560

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-
584561
function ComposerMentionBackspacePlugin() {
585562
const [editor] = useLexicalComposerContext();
586563

@@ -756,7 +733,10 @@ function ComposerPromptEditorInner({
756733
value: nextValue,
757734
cursor: nextCursor,
758735
};
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);
760740
});
761741
}, []);
762742

‎apps/web/src/composer-logic.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ describe("isCollapsedCursorAdjacentToMention", () => {
8585
expect(isCollapsedCursorAdjacentToMention("plain text", 6, "right")).toBe(false);
8686
});
8787

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+
8894
it("detects left adjacency only when cursor is directly after a mention", () => {
8995
const text = "open @AGENTS.md next";
9096
const mentionStart = "open ".length;

0 commit comments

Comments
 (0)