diff --git a/plugs/core/core.plug.yaml b/plugs/core/core.plug.yaml index de5c677..4033259 100644 --- a/plugs/core/core.plug.yaml +++ b/plugs/core/core.plug.yaml @@ -293,6 +293,8 @@ functions: path: ./text.ts:listifySelection command: name: "Text: Listify Selection" + key: "Ctrl-Shift-8" + mac: "Cmd-Shift-8" numberListifySelection: path: ./text.ts:numberListifySelection command: diff --git a/plugs/core/text.ts b/plugs/core/text.ts index 726af46..3828096 100644 --- a/plugs/core/text.ts +++ b/plugs/core/text.ts @@ -22,7 +22,18 @@ export async function quoteSelection() { export async function listifySelection() { let text = await editor.getText(); const selection = await editor.getSelection(); + + //if very first of doc, just add a bullet and end + if (selection.to == 0 && selection.from == 0) { + await editor.insertAtCursor("* ") + return + } + let from = selection.from; + if (text[from] == "\n") { + //end of line, need to find previous line break + from-- + } while (from >= 0 && text[from] !== "\n") { from--; } @@ -42,12 +53,11 @@ export async function numberListifySelection() { from++; text = text.slice(from, selection.to); let counter = 1; - text = `1. ${ - text.replaceAll(/\n(?!\n)/g, () => { - counter++; - return `\n${counter}. `; - }) - }`; + text = `1. ${text.replaceAll(/\n(?!\n)/g, () => { + counter++; + return `\n${counter}. `; + }) + }`; await editor.replaceRange(from, selection.to, text); }