diff --git a/lib/mod.ts b/lib/mod.ts index 0ad9bb7..0e5e398 100644 --- a/lib/mod.ts +++ b/lib/mod.ts @@ -226,10 +226,13 @@ export async function setup(document: Document, target: HTMLElement, backend: Ba workspace.commands.registerCommand({ id: "insert-child", title: "Insert Child", - action: (ctx: Context, name: string = "") => { + action: (ctx: Context, name: string = "", siblingIndex?: number) => { if (!ctx.node) return; const node = workspace.nodes.new(name); node.setParent(ctx.node); + if (siblingIndex !== undefined) { + node.setSiblingIndex(siblingIndex); + } if (ctx.node.panel) { workspace.setExpanded(ctx.node, true); } diff --git a/lib/ui/outline.tsx b/lib/ui/outline.tsx index 13898f4..56ba46b 100644 --- a/lib/ui/outline.tsx +++ b/lib/ui/outline.tsx @@ -83,7 +83,11 @@ export const OutlineNode: m.Component = { if (e.ctrlKey || e.shiftKey || e.metaKey || e.altKey) return; // cursor at end of text if (e.target.selectionStart === e.target.value.length) { - workspace.executeCommand("insert", {node}); + if (node.childCount() > 0 && workspace.getExpanded(node)) { + workspace.executeCommand("insert-child", {node}, "", 0); + } else { + workspace.executeCommand("insert", {node}); + } e.stopPropagation(); return; }