Skip to content

Commit 3bf48f0

Browse files
authored
lib: insert child on new node keydown (#291)
1 parent af1e2dc commit 3bf48f0

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/ui/node/new.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11

22
export const NewNode = {
33
view({attrs: {workbench, path}}) {
4-
const startNew = (e) => {
5-
workbench.executeCommand("insert-child", {node: path.node, path}, e.target.value);
6-
}
7-
const tabNew = (e) => {
4+
const keydown = (e) => {
85
if (e.key === "Tab") {
96
e.stopPropagation();
107
e.preventDefault();
118
if (node.childCount > 0) {
129
const lastchild = path.node.children[path.node.childCount-1];
1310
workbench.executeCommand("insert-child", {node: lastchild, path});
1411
}
12+
} else {
13+
workbench.executeCommand("insert-child", {node: path.node, path}, e.target.value);
1514
}
1615
}
1716
return (
@@ -23,8 +22,7 @@ export const NewNode = {
2322
<div class="flex grow">
2423
<input class="grow"
2524
type="text"
26-
oninput={startNew}
27-
onkeydown={tabNew}
25+
onkeydown={keydown}
2826
value={""}
2927
/>
3028
</div>

0 commit comments

Comments
 (0)