Keybinding to insert text

This might be a stupid question, but I want to insert a template mermaid graph into my notes using a hotkey. Essentially I would like to add a keybinding which always appends specific text behind the cursor. The documentation regarding keybindings only talks about the execution of commands, but not text-insertions. Is there any way to achieve this?

The easiest way is to define a custom command in the init.js and then add a keybinding that calls this command.

eg:
init.js

inkdrop.commands.add(
    document.body,
    'custom:insert-some-text',
    () => {
        const someText = `Some text!`;

        const mde = inkdrop.getActiveEditorOrThrowError()
        const cm = mde.cm
        const cursor = cm.getCursor()
        const line = cm.getLine(cursor.line)
        cm.replaceRange(someText, { line: cursor.line, ch: line.length })
    }
)

keymap.json

{
    ".CodeMirror textarea": {
        "ctrl-k ctrl-p": "custom:insert-some-text"
    }
}
2 Likes

Worked like a charm. Thank you very much!

1 Like