🐛 slash command fixes

This commit is contained in:
Nate Sesti 2023-12-24 17:42:43 -05:00
parent acc2d4fcc2
commit 1142ce9e60
3 changed files with 20 additions and 5 deletions

View file

@ -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;
},
}));

View file

@ -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,

View file

@ -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);
}