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

Call showAll on opening projects #9974

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion app/gui2/e2e/componentBrowser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('Graph Editor pans to Component Browser', async ({ page }) => {
await locate.graphNodeByBinding(page, 'final').click()
await page.mouse.move(100, 80)
await page.mouse.down({ button: 'middle' })
await page.mouse.move(100, 700)
await page.mouse.move(100, 1200)
await page.mouse.up({ button: 'middle' })
await expect(locate.graphNodeByBinding(page, 'final')).not.toBeInViewport()
await locate.graphEditor(page).press('Enter')
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/e2e/edgeRendering.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, Page, test } from '@playwright/test'
import { expect, test, type Page } from '@playwright/test'
import * as actions from './actions'
import { edgesFromNodeWithBinding, edgesToNodeWithBinding } from './locate'

Expand Down
2 changes: 1 addition & 1 deletion app/gui2/src/components/ColorPickerMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { injectGraphSelection } from '@/providers/graphSelection'
import { useGraphStore, type NodeId } from '@/stores/graph'
import { filterDefined } from '@/util/data/iterable'
import { tryGetSoleValue } from 'shared/util/data/iterable'
import { computed, ref, watch } from 'vue'
import { ref } from 'vue'

const emit = defineEmits<{
close: []
Expand Down
40 changes: 29 additions & 11 deletions app/gui2/src/components/GraphEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { Rect } from '@/util/data/rect'
import { Vec2 } from '@/util/data/vec2'
import { encoding, set } from 'lib0'
import { encodeMethodPointer } from 'shared/languageServerTypes'
import { computed, onMounted, ref, shallowRef, toRef, watch } from 'vue'
import { computed, onMounted, ref, shallowRef, toRef, watch, watchEffect } from 'vue'

const keyboard = provideKeyboard()
const graphStore = useGraphStore()
Expand All @@ -68,14 +68,31 @@ const suggestionDb = useSuggestionDbStore()
const viewportNode = ref<HTMLElement>()
onMounted(() => viewportNode.value?.focus())
const graphNavigator = provideGraphNavigator(viewportNode, keyboard)
useNavigatorStorage(graphNavigator, (enc) => {
// Navigator viewport needs to be stored separately for:
// - each project
// - each function within the project
encoding.writeVarString(enc, projectStore.name)
const methodPtr = graphStore.currentMethodPointer()
if (methodPtr != null) encodeMethodPointer(enc, methodPtr)
})
useNavigatorStorage(
graphNavigator,
(enc) => {
// Navigator viewport needs to be stored separately for:
// - each project
// - each function within the project
encoding.writeVarString(enc, projectStore.name)
const methodPtr = graphStore.currentMethodPointer()
if (methodPtr != null) encodeMethodPointer(enc, methodPtr)
},
waitInitializationAndPanToAll,
)

const stopInitialization = ref<() => void>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be reactive?

function waitInitializationAndPanToAll() {
stopInitialization.value?.()
stopInitialization.value = watchEffect(() => {
const nodesCount = [...graphStore.db.nodeIdToNode.keys()].length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodeIdToNode.size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, don’t ask how it appeared

const visibleNodeAreas = graphStore.visibleNodeAreas
if (nodesCount > 0 && visibleNodeAreas.length == nodesCount) {
zoomToSelected(true)
stopInitialization.value?.()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting it to undefined would allow it to be freed

}
})
}

function selectionBounds() {
if (!viewportNode.value) return
Expand All @@ -90,9 +107,10 @@ function selectionBounds() {
if (bounds.isFinite()) return bounds
}

function zoomToSelected() {
function zoomToSelected(skipAnimation: boolean = false) {
const bounds = selectionBounds()
if (bounds) graphNavigator.panAndZoomTo(bounds, 0.1, Math.max(1, graphNavigator.targetScale))
if (bounds)
graphNavigator.panAndZoomTo(bounds, 0.1, Math.max(1, graphNavigator.targetScale), skipAnimation)
}

function panToSelected() {
Expand Down
5 changes: 5 additions & 0 deletions app/gui2/src/composables/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function useNavigator(viewportNode: Ref<Element | undefined>, keyboard: K
rect: Rect,
minScale = PAN_AND_ZOOM_DEFAULT_SCALE_RANGE[0],
maxScale = PAN_AND_ZOOM_DEFAULT_SCALE_RANGE[1],
skipAnimation = false,
) {
if (!viewportNode.value) return
targetScale.value = Math.max(
Expand All @@ -87,6 +88,10 @@ export function useNavigator(viewportNode: Ref<Element | undefined>, keyboard: K
),
)
targetCenter.value = rect.center().finiteOrZero()
if (skipAnimation) {
scale.skip()
center.skip()
}
}

/** Pan to include the given prioritized list of coordinates.
Expand Down
6 changes: 5 additions & 1 deletion app/gui2/src/composables/navigatorStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Vec2 } from '@/util/data/vec2'
import { debouncedWatch, useLocalStorage } from '@vueuse/core'
import { encoding } from 'lib0'
import { xxHash128 } from 'shared/ast/ffi'
import { computed, watch } from 'vue'
import { computed, nextTick, watch } from 'vue'
import type { NavigatorComposable } from './navigator'

/**
Expand All @@ -12,10 +12,13 @@ import type { NavigatorComposable } from './navigator'
* @param reactiveStorageKeyEncoder A **reactive** encoder from which a storage key is derived. Data
* that is encoded in this function dictates the effective identity of stored viewport. Whenever the
* encoded data changes, the stored viewport value is restored to navigator.
* @param initializeViewport A function that will be called when no stored viewport is found for the
* current storage key.
*/
export function useNavigatorStorage(
navigator: NavigatorComposable,
reactiveStorageKeyEncoder: (enc: encoding.Encoder) => void,
initializeViewport: () => void,
) {
const graphViewportStorageKey = computed(() =>
xxHash128(encoding.encode(reactiveStorageKeyEncoder)),
Expand Down Expand Up @@ -64,6 +67,7 @@ export function useNavigatorStorage(

function restoreViewport(storageKey: string) {
const restored = storedViewport.value.get(storageKey)
if (restored == null) nextTick(initializeViewport)
const pos = restored ? Vec2.FromXY(restored).finiteOrZero() : Vec2.Zero
const scale = restored?.s ?? 1
navigator.setCenterAndScale(pos, scale)
Expand Down
Loading