Add link command
This commit is contained in:
parent
a29ea35937
commit
86823918cc
@ -215,6 +215,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:
|
||||||
|
@ -56,6 +56,23 @@ 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 = `[]()`;
|
||||||
|
if (textSelection.length > 0) {
|
||||||
|
try {
|
||||||
|
new URL(textSelection);
|
||||||
|
linkedText = `[](${textSelection})`;
|
||||||
|
} catch {
|
||||||
|
linkedText = `[${textSelection}]()`;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await replaceRange(selection.from, selection.to, linkedText)
|
||||||
|
}
|
||||||
|
|
||||||
export function wrapSelection(cmdDef: any) {
|
export function wrapSelection(cmdDef: any) {
|
||||||
return insertMarker(cmdDef.wrapper);
|
return insertMarker(cmdDef.wrapper);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user