Skip to content

Commit

Permalink
Fix node edits (#9111)
Browse files Browse the repository at this point in the history
* Prevent duplication of external IDs in syncTree

* trim component browser accepted value

* use flush post for visualization data watcher

* do not create empty nodes when closing component browser

* Lint

---------

Co-authored-by: Kaz <[email protected]>
  • Loading branch information
Frizi and kazcw authored Feb 20, 2024
1 parent 11a9e8d commit d415d13
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/gui2/shared/ast/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Token,
asOwned,
isTokenId,
newExternalId,
parentId,
rewriteRefs,
subtreeRoots,
Expand Down Expand Up @@ -848,6 +849,7 @@ function syncTree(
if (!syncRoot) {
parent.replaceChild(target.id, newContent)
newContent.fields.set('metadata', target.fields.get('metadata').clone())
target.fields.get('metadata').set('externalId', newExternalId())
}
const newRoot = syncRoot ? target : newContent
newRoot.visitRecursiveAst((ast) => {
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/src/components/ComponentBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function acceptSuggestion(index: Opt<Component> = null) {
}
function acceptInput() {
emit('accepted', input.code.value, input.importsToAdd())
emit('accepted', input.code.value.trim(), input.importsToAdd())
}
// === Key Events Handler ===
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/src/components/GraphEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function onComponentBrowserCommit(content: string, requiredImports: RequiredImpo
if (graphStore.editedNodeInfo) {
// We finish editing a node.
graphStore.setNodeContent(graphStore.editedNodeInfo.id, content)
} else {
} else if (content != '') {
// We finish creating a new node.
const metadata = undefined
const createdNode = graphStore.createNode(
Expand Down
4 changes: 3 additions & 1 deletion app/gui2/src/stores/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ export const useProjectStore = defineStore('project', () => {
executionContext.setVisualization(id, config)
onCleanup(() => executionContext.setVisualization(id, null))
},
{ immediate: true },
// Make sure to flush this watch in 'post', otherwise it might cause operations on stale
// ASTs just before the widget tree renders and cleans up the associated widget instances.
{ immediate: true, flush: 'post' },
)

return shallowRef(
Expand Down

0 comments on commit d415d13

Please sign in to comment.