Fix viewport bounds getting out of sync at times, like when toggling rulers

This commit is contained in:
Keavon Chambers
2024-07-28 05:42:27 -07:00
parent a4a513911d
commit 06177597ae
19 changed files with 124 additions and 116 deletions
+4 -11
View File
@@ -5,7 +5,6 @@ import { type Editor } from "@graphite/wasm-communication/editor";
import {
defaultWidgetLayout,
patchWidgetLayout,
TriggerRefreshBoundsOfViewports,
UpdateDocumentBarLayout,
UpdateDocumentModeLayout,
UpdateToolOptionsLayout,
@@ -13,6 +12,7 @@ import {
UpdateWorkingColorsLayout,
UpdateNodeGraphBarLayout,
TriggerGraphViewOverlay,
TriggerDelayedZoomCanvasToFitAll,
} from "@graphite/wasm-communication/messages";
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
@@ -83,16 +83,6 @@ export function createDocumentState(editor: Editor) {
});
});
// Other
editor.subscriptions.subscribeJsMessage(TriggerRefreshBoundsOfViewports, async () => {
// Wait to display the unpopulated document panel (missing: tools, options bar content, scrollbar positioning, and canvas)
await tick();
// Wait to display the populated document panel
await tick();
// Request a resize event so the viewport gets measured now that the canvas is populated and positioned correctly
window.dispatchEvent(new CustomEvent("resize"));
});
// Show or hide the graph view overlay
editor.subscriptions.subscribeJsMessage(TriggerGraphViewOverlay, (triggerGraphViewOverlay) => {
update((state) => {
@@ -100,6 +90,9 @@ export function createDocumentState(editor: Editor) {
return state;
});
});
editor.subscriptions.subscribeJsMessage(TriggerDelayedZoomCanvasToFitAll, () => {
setTimeout(() => editor.handle.zoomCanvasToFitAll(), 0);
});
return {
subscribe,