Skip to content

Commit

Permalink
lib: insert child on new node keydown (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcaTech authored Aug 8, 2023
1 parent af1e2dc commit 3bf48f0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/ui/node/new.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

export const NewNode = {
view({attrs: {workbench, path}}) {
const startNew = (e) => {
workbench.executeCommand("insert-child", {node: path.node, path}, e.target.value);
}
const tabNew = (e) => {
const keydown = (e) => {
if (e.key === "Tab") {
e.stopPropagation();
e.preventDefault();
if (node.childCount > 0) {
const lastchild = path.node.children[path.node.childCount-1];
workbench.executeCommand("insert-child", {node: lastchild, path});
}
} else {
workbench.executeCommand("insert-child", {node: path.node, path}, e.target.value);
}
}
return (
Expand All @@ -23,8 +22,7 @@ export const NewNode = {
<div class="flex grow">
<input class="grow"
type="text"
oninput={startNew}
onkeydown={tabNew}
onkeydown={keydown}
value={""}
/>
</div>
Expand Down

0 comments on commit 3bf48f0

Please sign in to comment.