From 1142ce9e6006f8e7b00d55e7494cfbb90bef1c06 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 24 Dec 2023 17:42:43 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20slash=20command=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/src/components/mainInput/MentionList.tsx | 7 +++++++ gui/src/components/mainInput/getSuggestion.ts | 4 ++-- gui/src/components/mainInput/resolveInput.ts | 14 +++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index d469daa01..5191e5428 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -166,6 +166,13 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { return true; } + if (event.key === " ") { + if (props.items.length === 1) { + enterHandler(); + return true; + } + } + return false; }, })); diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index be83d9a33..da325c149 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -146,9 +146,9 @@ export function getCommandSuggestion(availableSlashCommands: ComboBoxItem[]) { const items = ({ query }) => { return ( availableSlashCommands?.filter((slashCommand) => { - const sc = slashCommand.title.toLowerCase(); + const sc = slashCommand.title.substring(1).toLowerCase(); const iv = query.toLowerCase(); - return sc.startsWith(iv) && sc !== iv; + return sc.startsWith(iv); }) || [] ).map((provider) => ({ name: provider.title, diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index a6ea093c9..b3be37edb 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -20,6 +20,9 @@ async function resolveEditorContent( for (const p of editorState?.content) { if (p.type === "paragraph") { const [text, ctxItems] = resolveParagraph(p); + if (text === "") { + continue; + } paragraphs.push(text); contextItems.push(...ctxItems); } else if (p.type === "codeBlock") { @@ -47,7 +50,12 @@ async function resolveEditorContent( } } - const finalText = contextItemsText + "\n" + paragraphs.join("\n"); + if (contextItemsText !== "") { + contextItemsText += "\n"; + } + + const finalText = contextItemsText + paragraphs.join("\n"); + console.log(finalText, editorState?.content); return finalText; } @@ -60,8 +68,8 @@ function resolveParagraph(p: JSONContent) { } else if (child.type === "mention") { text += `@${child.attrs.label}`; contextItems.push(child.attrs.id); - } else if (child.type === "command") { - text += child.attrs.id; + } else if (child.type === "slashcommand") { + text += child.attrs.label; } else { console.warn("Unexpected child type", child.type); }