Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(markdown): open mentions after soft line breaks (#8280)

Eric Hayescb5925db02fe
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.ts
index 8d19db2f8e..3bdb8a007f 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
@@ -204,6 +204,30 @@ function paragraphWithCaret(text: string, offset: number) {
}
describe('@ trigger position', () => {
+ test.each([true, false])(
+ 'opens and filters after a soft line break (software keyboard: %s)',
+ (softwareKeyboard) => {
+ const harness = setup(paragraphWithCaret('hello', 5));
+ harness.editor.update(
+ () => {
+ const selection = $getSelection();
+ if ($isRangeSelection(selection)) selection.insertLineBreak();
+ },
+ { discrete: true }
+ );
+
+ harness.type('@jo', softwareKeyboard);
+
+ expect(harness.opened()).toBe(1);
+ expect(harness.searchTerms.at(-1)).toBe('jo');
+ expect(harness.children()).toEqual([
+ 'text:hello',
+ 'linebreak:\n',
+ 'inline-search:@jo',
+ ]);
+ }
+ );
+
test('opens and filters from software-keyboard input without an @ keydown', () => {
const harness = setup(paragraphWithCaret('hello ', 6));
@@ -214,6 +238,28 @@ describe('@ trigger position', () => {
expect(harness.children()).toEqual(['text:hello ', 'inline-search:@jo']);
});
+ test('leaves the following word intact after a soft line break', () => {
+ const harness = setup(paragraphWithCaret('helloworld', 5));
+ harness.editor.update(
+ () => {
+ const selection = $getSelection();
+ if ($isRangeSelection(selection)) selection.insertLineBreak();
+ },
+ { discrete: true }
+ );
+
+ harness.type('@jo');
+
+ expect(harness.opened()).toBe(1);
+ expect(harness.searchTerms.at(-1)).toBe('jo');
+ expect(harness.children()).toEqual([
+ 'text:hello',
+ 'linebreak:\n',
+ 'inline-search:@jo',
+ 'text:world',
+ ]);
+ });
+
test('keeps software-keyboard @ literal inside a word', () => {
const harness = setup(paragraphWithCaret('hello', 3));
@@ -360,6 +406,30 @@ describe.each([
{ name: 'snippets', symbol: ';', plugin: snippetsPlugin },
{ name: 'tags', symbol: '#', plugin: tagsPlugin },
])('$name menu input', ({ symbol, plugin }) => {
+ test.each([true, false])(
+ 'opens after a soft line break (software keyboard: %s)',
+ (softwareKeyboard) => {
+ const harness = setup(paragraphWithCaret('hello', 5), plugin);
+ harness.editor.update(
+ () => {
+ const selection = $getSelection();
+ if ($isRangeSelection(selection)) selection.insertLineBreak();
+ },
+ { discrete: true }
+ );
+
+ harness.type(`${symbol}test`, softwareKeyboard);
+
+ expect(harness.opened()).toBe(1);
+ expect(harness.searchTerms.at(-1)).toBe('test');
+ expect(harness.children()).toEqual([
+ 'text:hello',
+ 'linebreak:\n',
+ `inline-search:${symbol}test`,
+ ]);
+ }
+ );
+
test.each([true, false])(
'opens once and filters (software keyboard: %s)',
(softwareKeyboard) => {
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index 1c30045747..73987ba6c3 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -2304,7 +2304,9 @@ table cells is preserved in paragraphs when the editor opens the document.
`@` opens the mention menu wherever the caret starts a word, including directly
in front of existing text — the menu opens empty there instead of searching for
-the word ahead of the caret. Typed inside a word (`he@llo`) it stays literal text.
+the word ahead of the caret. It also opens immediately after a soft line break:
+type a word, press Shift+Enter, then type `@` and a name to filter the menu.
+Typed inside a word (`he@llo`) it stays literal text.
On Android, verify this with the software keyboard: tap `@`, type a name to
filter, and tap a result to insert a single mention. The menu should remain
visible above the keyboard while typing.
diff --git a/packages/lexical-core/nodes/InlineSearchNode.ts b/packages/lexical-core/nodes/InlineSearchNode.ts
index feaf464831..e0027f72c5 100644
--- a/packages/lexical-core/nodes/InlineSearchNode.ts
+++ b/packages/lexical-core/nodes/InlineSearchNode.ts
@@ -4,6 +4,7 @@ import {
$createTextNode,
$getNodeByKey,
$getSelection,
+ $isElementNode,
$isRangeSelection,
$isTextNode,
type EditorConfig,
@@ -51,6 +52,14 @@ export const SEARCH_NODE_TYPE_VALUES = {
* happens where formatting splits one word across text nodes.
*/
function $textBeforeCaret(anchorNode: LexicalNode, offset: number): string {
+ // Element offsets count children, as after inserting a soft line break.
+ if ($isElementNode(anchorNode)) {
+ return anchorNode
+ .getChildren()
+ .slice(0, offset)
+ .map((node) => node.getTextContent())
+ .join('');
+ }
const text = anchorNode.getTextContent().slice(0, offset);
if (text !== '' || !$isTextNode(anchorNode)) return text;
const previous = anchorNode.getPreviousSibling();
@@ -90,9 +99,13 @@ export function validTriggerPosition(
if (after === null) return true;
- const afterText = anchorNode
- .getTextContent()
- .slice(selection.anchor.offset);
+ const afterText = $isElementNode(anchorNode)
+ ? anchorNode
+ .getChildren()
+ .slice(selection.anchor.offset)
+ .map((node) => node.getTextContent())
+ .join('')
+ : anchorNode.getTextContent().slice(selection.anchor.offset);
return isEmptyOrMatches(afterText, after);
});
}