Skip to content

Commit ec59f4b

Browse files
committed
demo: Enter at end of node text with expanded children will insert a child node. closes #29
1 parent 28e6387 commit ec59f4b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/mod.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@ export async function setup(document: Document, target: HTMLElement, backend: Ba
226226
workspace.commands.registerCommand({
227227
id: "insert-child",
228228
title: "Insert Child",
229-
action: (ctx: Context, name: string = "") => {
229+
action: (ctx: Context, name: string = "", siblingIndex?: number) => {
230230
if (!ctx.node) return;
231231
const node = workspace.nodes.new(name);
232232
node.setParent(ctx.node);
233+
if (siblingIndex !== undefined) {
234+
node.setSiblingIndex(siblingIndex);
235+
}
233236
if (ctx.node.panel) {
234237
workspace.setExpanded(ctx.node, true);
235238
}

lib/ui/outline.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export const OutlineNode: m.Component<Attrs, State> = {
8383
if (e.ctrlKey || e.shiftKey || e.metaKey || e.altKey) return;
8484
// cursor at end of text
8585
if (e.target.selectionStart === e.target.value.length) {
86-
workspace.executeCommand("insert", {node});
86+
if (node.childCount() > 0 && workspace.getExpanded(node)) {
87+
workspace.executeCommand("insert-child", {node}, "", 0);
88+
} else {
89+
workspace.executeCommand("insert", {node});
90+
}
8791
e.stopPropagation();
8892
return;
8993
}

0 commit comments

Comments
 (0)