From cb6f4562ded756a92fb29cecc764a1bc0241b2b0 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Sat, 28 Mar 2026 23:12:33 +0200 Subject: [PATCH] add / action trigger to InlineMentionEditor --- .../assistant-ui/inline-mention-editor.tsx | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/surfsense_web/components/assistant-ui/inline-mention-editor.tsx b/surfsense_web/components/assistant-ui/inline-mention-editor.tsx index 66389cade..3994de1d5 100644 --- a/surfsense_web/components/assistant-ui/inline-mention-editor.tsx +++ b/surfsense_web/components/assistant-ui/inline-mention-editor.tsx @@ -40,6 +40,8 @@ interface InlineMentionEditorProps { placeholder?: string; onMentionTrigger?: (query: string) => void; onMentionClose?: () => void; + onActionTrigger?: (query: string) => void; + onActionClose?: () => void; onSubmit?: () => void; onChange?: (text: string, docs: MentionedDocument[]) => void; onDocumentRemove?: (docId: number, docType?: string) => void; @@ -90,6 +92,8 @@ export const InlineMentionEditor = forwardRef 0) { + const range = selection.getRangeAt(0); + const textNode = range.startContainer; + + if (textNode.nodeType === Node.TEXT_NODE) { + const textContent = textNode.textContent || ""; + const cursorPos = range.startOffset; + + let slashIndex = -1; + for (let i = cursorPos - 1; i >= 0; i--) { + if (textContent[i] === "/") { + slashIndex = i; + break; + } + if (textContent[i] === " " || textContent[i] === "\n") { + break; + } + } + + if (slashIndex !== -1 && (slashIndex === 0 || textContent[slashIndex - 1] === " " || textContent[slashIndex - 1] === "\n")) { + const query = textContent.slice(slashIndex + 1, cursorPos); + if (!query.startsWith(" ")) { + shouldTriggerAction = true; + actionQuery = query; + } + } + } + } + // If no @ found before cursor, check if text contains @ at all // If text is empty or doesn't contain @, close the mention if (!shouldTriggerMention) { @@ -533,9 +570,15 @@ export const InlineMentionEditor = forwardRef