Skip to content

Commit

Permalink
demo: backspace deleting a node put selection on above node, collapse…
Browse files Browse the repository at this point in the history
…s if now empty. closes #53
  • Loading branch information
progrium committed Mar 21, 2023
1 parent c68fb12 commit b209b4d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
25 changes: 24 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions lib/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,18 @@ export async function setup(document: Document, target: HTMLElement, backend: Ba
action: (ctx: Context) => {
if (!ctx.node) return;
if (ctx.node.ID.startsWith("@")) return;
const prev = ctx.node.getPrevSibling();
const above = workbench.workspace.findAbove(ctx.panel.headNode, ctx.node);
ctx.node.destroy();
m.redraw.sync();
if (prev) {
if (above) {
let pos = 0;
if (ctx.event && ctx.event.key === "Backspace") {
pos = prev.getName().length;
pos = above.getName().length;
}
if (above.childCount() === 0) {
workbench.workspace.setExpanded(ctx.panel.headNode, above, false);
}
workbench.focus(prev, ctx.panel, pos);
workbench.focus(above, ctx.panel, pos);
}
}
});
Expand Down

0 comments on commit b209b4d

Please # to comment.