1
0

A few more text manipulation commands

This commit is contained in:
Zef Hemel
2022-06-23 17:59:18 +02:00
parent b22775fcc4
commit e74caf0055
5 changed files with 40 additions and 5 deletions
+8
View File
@@ -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:
+30
View File
@@ -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("**");
}