mirror of https://github.com/usememos/memos.git
feat(commands): enable cursor offsetting after running command
also add additional commands
This commit is contained in:
parent
699ea0f8fe
commit
801cc1e9db
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ export type Command = {
|
|||
name: string;
|
||||
description?: string;
|
||||
run: () => string;
|
||||
cursorOffset?: number;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue