A few more text manipulation commands
This commit is contained in:
@@ -139,6 +139,14 @@ functions:
|
||||
name: "Text: Quote Selection"
|
||||
key: "Ctrl->"
|
||||
mac: "Cmd-Shift-."
|
||||
listifySelection:
|
||||
path: ./text.ts:listifySelection
|
||||
command:
|
||||
name: "Text: Listify Selection"
|
||||
numberListifySelection:
|
||||
path: ./text.ts:numberListifySelection
|
||||
command:
|
||||
name: "Text: Number Listify Selection"
|
||||
bold:
|
||||
path: ./text.ts:boldCommand
|
||||
command:
|
||||
|
||||
@@ -26,6 +26,36 @@ export async function quoteSelection() {
|
||||
await replaceRange(from, selection.to, text);
|
||||
}
|
||||
|
||||
export async function listifySelection() {
|
||||
let text = await getText();
|
||||
const selection = await getSelection();
|
||||
let from = selection.from;
|
||||
while (from >= 0 && text[from] !== "\n") {
|
||||
from--;
|
||||
}
|
||||
from++;
|
||||
text = text.slice(from, selection.to);
|
||||
text = `* ${text.replaceAll(/\n(?!\n)/g, "\n* ")}`;
|
||||
await replaceRange(from, selection.to, text);
|
||||
}
|
||||
|
||||
export async function numberListifySelection() {
|
||||
let text = await getText();
|
||||
const selection = await getSelection();
|
||||
let from = selection.from;
|
||||
while (from >= 0 && text[from] !== "\n") {
|
||||
from--;
|
||||
}
|
||||
from++;
|
||||
text = text.slice(from, selection.to);
|
||||
let counter = 1;
|
||||
text = `1. ${text.replaceAll(/\n(?!\n)/g, () => {
|
||||
counter++;
|
||||
return `\n${counter}. `;
|
||||
})}`;
|
||||
await replaceRange(from, selection.to, text);
|
||||
}
|
||||
|
||||
export function boldCommand() {
|
||||
return insertMarker("**");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user