Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(mentions): filter the @ menu while an Android keyboard composes a word (#9236)
Peter Chinman6c148e1a2593
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/tests/mentionTrigger.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/tests/mentionTrigger.test.tsindex cd09d7f4ff..bd41722dd6 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/tests/mentionTrigger.test.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/tests/mentionTrigger.test.ts@@ -238,6 +238,25 @@ describe('@ trigger position', () => {expect(harness.children()).toEqual(['text:hello ', 'inline-search:@jo']);});+ test('filters while a software keyboard is still composing the word', () => {+ const harness = setup(paragraphWithCaret('hello ', 6));+ harness.type('@', true);++ // Lexical keeps a zero-width space ahead of a word the keyboard is still+ // composing, and removes it only when the word is committed.+ harness.editor.update(+ () => {+ const selection = $getSelection();+ if ($isRangeSelection(selection)) selection.insertText('\u200bjo');+ },+ { discrete: true }+ );+ harness.editor.read(() => {});++ expect(harness.opened()).toBe(1);+ expect(harness.searchTerms.at(-1)).toBe('jo');+ });+test('leaves the following word intact after a soft line break', () => {const harness = setup(paragraphWithCaret('helloworld', 5));harness.editor.update(diff --git a/packages/lexical-core/nodes/InlineSearchNode.ts b/packages/lexical-core/nodes/InlineSearchNode.tsindex e0027f72c5..0b3da85d0a 100644--- a/packages/lexical-core/nodes/InlineSearchNode.ts+++ b/packages/lexical-core/nodes/InlineSearchNode.ts@@ -112,6 +112,22 @@ export function validTriggerPosition(const CLEAN_REGEX = /^[@:\/;#]/g; // Matches menu triggers to clean the search term.+/**+ * While a keyboard composes a word, Lexical keeps a zero-width space in the+ * node's text and removes it only when the word is committed. Android+ * keyboards compose every word, so without this the search would never match+ * until the word ends.+ */+const COMPOSITION_PLACEHOLDER_REGEX = /\u200b/g;++/** The search term typed after a menu trigger. */+function inlineSearchTerm(text: string) {+ return text+ .replace(COMPOSITION_PLACEHOLDER_REGEX, '')+ .trim()+ .replace(CLEAN_REGEX, '');+}+export class InlineSearchNode extends TextNode {static getType() {return 'inline-search';@@ -209,10 +225,7 @@ export function $handleInlineSearchNodeMutation(const search = state.read(() =>$getNodeByKey(nodeKey)?.getTextContent());- if (search) {- let cleanedSearch = search.trim().replace(CLEAN_REGEX, '');- actions.onUpdate(cleanedSearch);- }+ if (search) actions.onUpdate(inlineSearchTerm(search));}}}