From d415d133bb04306a42297509c0d897520a6e8260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Grabarz?= Date: Tue, 20 Feb 2024 22:40:50 +0100 Subject: [PATCH] Fix node edits (#9111) * 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 --- app/gui2/shared/ast/parse.ts | 2 ++ app/gui2/src/components/ComponentBrowser.vue | 2 +- app/gui2/src/components/GraphEditor.vue | 2 +- app/gui2/src/stores/project/index.ts | 4 +++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/gui2/shared/ast/parse.ts b/app/gui2/shared/ast/parse.ts index d1b5020d8085..ce118e87d6a3 100644 --- a/app/gui2/shared/ast/parse.ts +++ b/app/gui2/shared/ast/parse.ts @@ -4,6 +4,7 @@ import { Token, asOwned, isTokenId, + newExternalId, parentId, rewriteRefs, subtreeRoots, @@ -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) => { diff --git a/app/gui2/src/components/ComponentBrowser.vue b/app/gui2/src/components/ComponentBrowser.vue index 3a902977785c..10a56c279348 100644 --- a/app/gui2/src/components/ComponentBrowser.vue +++ b/app/gui2/src/components/ComponentBrowser.vue @@ -319,7 +319,7 @@ function acceptSuggestion(index: Opt = null) { } function acceptInput() { - emit('accepted', input.code.value, input.importsToAdd()) + emit('accepted', input.code.value.trim(), input.importsToAdd()) } // === Key Events Handler === diff --git a/app/gui2/src/components/GraphEditor.vue b/app/gui2/src/components/GraphEditor.vue index 6c39a92e6b16..a217310b278f 100644 --- a/app/gui2/src/components/GraphEditor.vue +++ b/app/gui2/src/components/GraphEditor.vue @@ -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( diff --git a/app/gui2/src/stores/project/index.ts b/app/gui2/src/stores/project/index.ts index 429ac384c7f3..32a6fa91830c 100644 --- a/app/gui2/src/stores/project/index.ts +++ b/app/gui2/src/stores/project/index.ts @@ -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(