add split at point no child

This commit is contained in:
celeste 2023-07-24 03:31:41 -04:00
parent 436bac527c
commit f95d048c71
4 changed files with 29 additions and 8 deletions

View file

@ -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

28
main.ts
View file

@ -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;

View file

@ -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",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-loom",
"version": "1.15.2",
"version": "1.16.0",
"description": "Loom in Obsidian",
"main": "main.js",
"scripts": {