From e74caf00551666d13565f6955d144fce65b15f72 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 23 Jun 2022 17:59:18 +0200 Subject: [PATCH] A few more text manipulation commands --- README.md | 4 ---- package-lock.json | 2 +- package.json | 1 + packages/plugs/core/core.plug.yaml | 8 ++++++++ packages/plugs/core/text.ts | 30 ++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce20aa02..586696da 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,6 @@ npm run build npm install # Build plugs (ctrl-c after done, it's watching) npm run plugs -# Symlink in the default set of plugs into your space -cd pages -ln -s ../packages/plugs/dist _plug -cd .. # Launch server npm run server ``` diff --git a/package-lock.json b/package-lock.json index fd95be22..b10099b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26512,7 +26512,7 @@ "nodemon": "^2.0.15", "parcel": "2.5.0", "typescript": "^4.6.2", - "uuid": "*", + "uuid": "^8.3.2", "vm2": "^3.9.9", "ws": "^8.5.0", "yaml": "^1.10.2", diff --git a/package.json b/package.json index 17e9b2d1..7f15ce80 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "watch": "rm -rf .parcel-cache && parcel watch --no-hmr packages/{web,server,plugos,plugs} desktop", "clean": "rm -rf .parcel-cache packages/*/dist", + "nuke": "rm -rf node_modules && npm run clean", "build": "parcel build packages/{web,server,plugos}", "plugs": "cd packages/plugs && npm run watch", "server": "nodemon -w packages/server/dist --exec 'silverbullet pages'", diff --git a/packages/plugs/core/core.plug.yaml b/packages/plugs/core/core.plug.yaml index 0567193c..b6389c51 100644 --- a/packages/plugs/core/core.plug.yaml +++ b/packages/plugs/core/core.plug.yaml @@ -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: diff --git a/packages/plugs/core/text.ts b/packages/plugs/core/text.ts index f853e66c..73c2a55d 100644 --- a/packages/plugs/core/text.ts +++ b/packages/plugs/core/text.ts @@ -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("**"); }