Merge branch 'main' of github.com:silverbulletmd/silverbullet

website
Zef Hemel 2022-07-11 13:58:44 +02:00
commit 8a10369d91
2 changed files with 25 additions and 0 deletions

View File

@ -221,6 +221,12 @@ functions:
path: ./text.ts:numberListifySelection path: ./text.ts:numberListifySelection
command: command:
name: "Text: Number Listify Selection" name: "Text: Number Listify Selection"
linkSelection:
path: ./text.ts:linkSelection
command:
name: "Text: Link Selection"
key: "Ctrl-Shift-k"
mac: "Cmd-Shift-k"
bold: bold:
path: ./text.ts:wrapSelection path: ./text.ts:wrapSelection
command: command:

View File

@ -56,6 +56,25 @@ export async function numberListifySelection() {
await replaceRange(from, selection.to, text); await replaceRange(from, selection.to, text);
} }
export async function linkSelection() {
const text = await getText();
const selection = await getSelection();
const textSelection = text.slice(selection.from, selection.to);
let linkedText = `[]()`;
let pos = 1;
if (textSelection.length > 0) {
try {
new URL(textSelection);
linkedText = `[](${textSelection})`;
} catch {
linkedText = `[${textSelection}]()`;
pos = linkedText.length - 1;
}
}
await replaceRange(selection.from, selection.to, linkedText)
await moveCursor(selection.from + pos);
}
export function wrapSelection(cmdDef: any) { export function wrapSelection(cmdDef: any) {
return insertMarker(cmdDef.wrapper); return insertMarker(cmdDef.wrapper);
} }