Skip to content

Commit

Permalink
fix viewport jumping when adding new nodes (#10920)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
vitvakatu and mergify[bot] authored Aug 31, 2024
1 parent 124147d commit de5ef92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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

0 comments on commit de5ef92

Please sign in to comment.