feat(commands): enable cursor offsetting after running command

also add additional commands
This commit is contained in:
Tobias Waslowski 2025-08-07 09:02:14 +02:00
parent 699ea0f8fe
commit 801cc1e9db
No known key found for this signature in database
GPG Key ID: 30013DA2D0F8AFAD
3 changed files with 30 additions and 0 deletions

View File

@ -49,6 +49,9 @@ const CommandSuggestions = observer(({ editorRef, editorActions, commands }: Pro
const [word, index] = getCurrentWord();
editorActions.current.removeText(index, word.length);
editorActions.current.insertText(cmd.run());
if (cmd.cursorOffset) {
editorActions.current.setCursorPosition(cmd.cursorOffset);
}
hide();
};

View File

@ -5,10 +5,36 @@ export const editorCommands: Command[] = [
name: "todo",
description: "Insert a task checkbox",
run: () => "- [ ] ",
cursorOffset: 6,
},
{
name: "code",
description: "Insert a code block",
run: () => "```\n\n```",
cursorOffset: 4,
},
{
name: "link",
description: "Insert a link",
run: () => "[text](url)",
cursorOffset: 1,
},
{
name: "table-2",
description: "Insert a table",
run: () => "| Header | Header |\n| ------ | ------ |\n| Cell | Cell |",
cursorOffset: 1,
},
{
name: "table-3",
description: "Insert a table",
run: () => "| Header | Header | Header |\n| ------ | ------ | ------ |\n| Cell | Cell | Cell |",
cursorOffset: 1,
},
{
name: "highlight",
description: "Insert highlighted text",
run: () => "==text==",
cursorOffset: 2,
},
];

View File

@ -2,4 +2,5 @@ export type Command = {
name: string;
description?: string;
run: () => string;
cursorOffset?: number;
};