Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewport jumping when adding new nodes #10920

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/gui2/src/components/GraphEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import type { RequiredImport } from '@/stores/graph/imports'
import { useProjectStore } from '@/stores/project'
import { provideSuggestionDbStore } from '@/stores/suggestionDatabase'
import { suggestionDocumentationUrl, type Typename } from '@/stores/suggestionDatabase/entry'
import { applyUpdates } from '@/stores/suggestionDatabase/lsUpdate'
import { provideVisualizationStore } from '@/stores/visualization'
import { bail } from '@/util/assert'
import type { AstId } from '@/util/ast/abstract'
Expand All @@ -72,7 +71,6 @@ import {
type ComponentInstance,
} from 'vue'
import { encodeMethodPointer } from 'ydoc-shared/languageServerTypes'
import * as lsTypes from 'ydoc-shared/languageServerTypes/suggestions'
import * as iterable from 'ydoc-shared/util/data/iterable'
import { isDevMode } from 'ydoc-shared/util/detect'

Expand Down
2 changes: 1 addition & 1 deletion app/gui2/src/composables/nodeCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function useNodeCreation(
}
insertNodeStatements(edit.getVersion(methodAst.value).bodyAsBlock(), statements)
})
onCreated(created)
graphStore.doAfterUpdate(() => onCreated(created))
}

/** We resolve import conflicts and substitute identifiers if needed. */
Expand Down
12 changes: 12 additions & 0 deletions app/gui2/src/stores/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,20 @@ export const { injectFn: useGraphStore, provideFn: provideGraphStore } = createC

const watchContext = useWatchContext()

const afterUpdate: (() => void)[] = []

/** `func` callback will be executed once after next call to `updateNodes`. */
function doAfterUpdate(func: () => void) {
afterUpdate.push(func)
}

watchEffect(() => {
if (!methodAst.value.ok) return
db.updateNodes(methodAst.value.value, watchContext)
for (const cb of afterUpdate) {
cb()
}
afterUpdate.length = 0
})

watchEffect(() => {
Expand Down Expand Up @@ -690,6 +701,7 @@ export const { injectFn: useGraphStore, provideFn: provideGraphStore } = createC
return proxyRefs({
db: markRaw(db),
mockExpressionUpdate,
doAfterUpdate,
editedNodeInfo,
moduleSource,
nodeRects,
Expand Down
Loading