From f95d048c71d3c426a0aa8983aa012343f530d37a Mon Sep 17 00:00:00 2001 From: celeste Date: Mon, 24 Jul 2023 03:31:41 -0400 Subject: [PATCH] add split at point no child --- README.md | 5 +++-- main.ts | 28 ++++++++++++++++++++++++---- manifest.json | 2 +- package.json | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 19806cc..02cb0b2 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ If you are interested in funding this plugin's development, you can **[support m - generate - `Ctrl+Space` - generate siblings - `Ctrl+Shift+Space` -- split at point - `Alt+c` +- split at point - `Alt+s` +- split at point and create child - `Alt+c` - delete (current node) - `Alt+Backspace` - merge (current node) with parent - `Alt+m` @@ -43,7 +44,7 @@ Alternatively, you can build Loom from source: 3. Go to the "Community plugins" tab in Obsidian settings, then enable "Loom" 4. To update, go to the repository and `git pull; npm i; npm run build`, then disable and re-enable Loom -**If you are using MacOS:** a few hotkeys -- `Alt+c` and `Alt+m` -- are bound to special characters. You can either: +**If you are using MacOS:** a few hotkeys -- `Alt+s`, `Alt+c`, and `Alt+m` -- are bound to special characters. You can either: 1. Disable MacOS's special character shortcuts, as explained here: https://superuser.com/questions/941286/disable-default-option-key-binding 2. Rebind the Loom hotkeys you want to use in the Hotkeys tab in Settings diff --git a/main.ts b/main.ts index 6495616..3b492ba 100644 --- a/main.ts +++ b/main.ts @@ -205,7 +205,7 @@ export default class LoomPlugin extends Plugin { return text; } - breakAtPoint(file: TFile): string { + breakAtPoint(file: TFile): (string | null)[] { // split the current node into: // - parent node with text before cursor // - child node with text after cursor @@ -230,7 +230,7 @@ export default class LoomPlugin extends Plugin { if (i < familyTexts[n].length) break; // if the cursor is at the end of the last node, don't split, just return the current node if (n === family.length - 1) - return current; + return [current, null]; i -= familyTexts[n].length; n++; } @@ -257,7 +257,7 @@ export default class LoomPlugin extends Plugin { // move the children to under the after node children.forEach((child) => (child.parentId = childId)); - return parentNode; + return [parentNode, childId]; } async onload() { @@ -369,6 +369,16 @@ export default class LoomPlugin extends Plugin { withState(checking, (state) => { this.app.workspace.trigger("loom:break-at-point", state.current); }), + hotkeys: [{ modifiers: ["Alt"], key: "s" }], + }); + + this.addCommand({ + id: "break-at-point-create-child", + name: "Split at current point and create child", + checkCallback: (checking: boolean) => + withState(checking, (state) => { + this.app.workspace.trigger("loom:break-at-point-create-child", state.current); + }), hotkeys: [{ modifiers: ["Alt"], key: "c" }], }); @@ -776,7 +786,17 @@ export default class LoomPlugin extends Plugin { // @ts-expect-error this.app.workspace.on("loom:break-at-point", () => this.withFile((file) => { - const parentId = this.breakAtPoint(file); + const [, childId] = this.breakAtPoint(file); + if (childId) this.app.workspace.trigger("loom:switch-to", childId); + }) + ) + ); + + this.registerEvent( + // @ts-expect-error + this.app.workspace.on("loom:break-at-point-create-child", () => + this.withFile((file) => { + const [parentId] = this.breakAtPoint(file); if (parentId !== undefined) { const [newId, newNode] = this.newNode("", parentId); this.state[file.path].nodes[newId] = newNode; diff --git a/manifest.json b/manifest.json index ccb7930..1b28a16 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "loom", "name": "Loom", - "version": "1.15.2", + "version": "1.16.0", "minAppVersion": "0.15.0", "description": "Loom in Obsidian", "author": "celeste", diff --git a/package.json b/package.json index 8b45734..1e337bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-loom", - "version": "1.15.2", + "version": "1.16.0", "description": "Loom in Obsidian", "main": "main.js", "scripts": {