Skip to content

Commit

Permalink
Fix and optimize code node
Browse files Browse the repository at this point in the history
  • Loading branch information
YYsuni committed Aug 2, 2023
1 parent 7396d47 commit 03f7b7e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/editable-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const _EditableNode = forwardRef<{ getContent: () => string; getType: () => Node
const [type, setType] = useState<NodeType>(node.type || 'text')
const [code, setCode] = useState(node.code || '')

// Update node object values
useEffect(() => {
node.value = value
node.type = type
node.code = code
}, [value, type, code])

// New node can be edited immediately.
useEffect(() => {
if (node.isNew) {
Expand Down Expand Up @@ -93,7 +100,10 @@ const _EditableNode = forwardRef<{ getContent: () => string; getType: () => Node
_editor.onDidBlurEditorWidget(end)

_editor.onKeyDown(event => {
if (event.keyCode === 9) end()
if (event.keyCode === 9) {
end()
setTimeout(() => innerRef.current?.focus())
}
})

setEditor(_editor)
Expand Down

0 comments on commit 03f7b7e

Please sign in to comment.