Skip to content

Commit

Permalink
add split at point no child
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicoptima committed Jul 24, 2023
1 parent 436bac5 commit f95d048
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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
28 changes: 24 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++;
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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" }],
});

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-loom",
"version": "1.15.2",
"version": "1.16.0",
"description": "Loom in Obsidian",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit f95d048

Please sign in to comment.