From d1dacd805458d41d2bfa6155c63371a0c7fba190 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Thu, 19 Nov 2026 23:03:34 +0000 Subject: [PATCH 01/14] Size scrollable area to 1.5x canvas contents (#782) Replace the fixed 100x scrollable area with 1.5x the extent of the items on the canvas, using a new Canvas::contentBounds(). The area is resized when the scroll position is reset and after scrolling stops. Also fix swapped width/height in RESET_ZOOM handler, and avoid a stuck moveOnScroll counter when programmatic scrolling generates no event. Co-Authored-By: Claude Sonnet 5.5 --- .../WindowUtility/window-utility.service.ts | 38 +++++++++++++++---- .../src/lib/wiring/wiring.component.ts | 28 +++++++++++--- model/canvas.h | 8 ++++ 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts b/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts index 7b448b3d7..7c2e0aaa3 100644 --- a/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts +++ b/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts @@ -15,7 +15,8 @@ export class WindowUtilityService { private scrollableAreaWidth = null; private scrollableAreaHeight = null; private mainWindowId = 1; - SCROLLABLE_AREA_FACTOR = 100; + // scrollable area is this multiple of the extent of the canvas contents + SCROLLABLE_AREA_FACTOR = 1.5; constructor(private electronService: ElectronService) { } @@ -35,12 +36,9 @@ export class WindowUtilityService { bodyElement.clientHeight - this.minskyCanvasContainer.offsetTop + 'px'; if (!this.scrollableAreaWidth || !this.scrollableAreaHeight) { - // Scrollable area size should not change - - this.scrollableAreaWidth = - bodyElement.clientWidth * this.SCROLLABLE_AREA_FACTOR; - this.scrollableAreaHeight = - bodyElement.clientHeight * this.SCROLLABLE_AREA_FACTOR; + // initial size, until updateScrollableArea is called with the contents' bounds + this.scrollableAreaWidth = bodyElement.clientWidth * 3; + this.scrollableAreaHeight = bodyElement.clientHeight * 3; } this.minskyCanvasElement.style.width = this.scrollableAreaWidth + 'px'; this.minskyCanvasElement.style.height = this.scrollableAreaHeight + 'px'; @@ -57,6 +55,32 @@ export class WindowUtilityService { } } + /** + * Resize the scrollable area to SCROLLABLE_AREA_FACTOR times the extent of + * the canvas contents. The pan position (scrollable area centre minus + * scroll offset) lies within +/- half the excess over the drawable area. + * @param bounds [x0,y0,x1,y1] of canvas contents in window coordinates + * @param pos current pan position [x,y] + * @returns true if the scrollable area changed + */ + public updateScrollableArea(bounds: number[], pos: number[]): boolean { + if (!this.minskyCanvasElement || !bounds || bounds.length < 4) return false; + const size = (b0: number, b1: number, p: number, drawable: number) => { + // contents' extent relative to the unpanned origin + const extent = Math.max(Math.abs(b0 - p), Math.abs(b1 - p), 0); + const half = this.SCROLLABLE_AREA_FACTOR * extent; + return Math.ceil(Math.max(drawable + 2 * half, 2 * drawable)); + }; + const w = size(bounds[0], bounds[2], pos[0], this.drawableWidth); + const h = size(bounds[1], bounds[3], pos[1], this.drawableHeight); + if (w === this.scrollableAreaWidth && h === this.scrollableAreaHeight) return false; + this.scrollableAreaWidth = w; + this.scrollableAreaHeight = h; + this.minskyCanvasElement.style.width = w + 'px'; + this.minskyCanvasElement.style.height = h + 'px'; + return true; + } + public scrollToCenter() { this.minskyCanvasElement.scrollTop = this.scrollableAreaHeight / 2; this.minskyCanvasElement.scrollLeft = this.scrollableAreaWidth / 2; diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index a3bb8c10f..0bf20d852 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -62,7 +62,6 @@ export class WiringComponent implements OnInit, OnDestroy { private setupEventListenersForCanvas(minskyCanvasContainer: HTMLElement) { const minskyCanvasElement = document.getElementById('main-minsky-canvas') as HTMLElement; - const scrollableArea = this.windowUtilityService.getScrollableArea(); var moveOnScroll=0; // avoid moving when programmatically setting scroll bars const tabElements = document.getElementsByClassName('tab'); @@ -76,16 +75,26 @@ export class WiringComponent implements OnInit, OnDestroy { } this.cmService.resetScroll=async ()=>{ - ++moveOnScroll; var pos= await this.electronService.currentTabPosition(); - minskyCanvasContainer.scrollLeft=scrollableArea.width/2 - pos[0]; - minskyCanvasContainer.scrollTop=scrollableArea.height/2 - pos[1]; + try { + const bounds=await this.electronService.minsky.canvas.contentBounds(); + this.windowUtilityService.updateScrollableArea(bounds,pos); + } catch (e) {console.error(e);} + const scrollableArea = this.windowUtilityService.getScrollableArea(); + // only count scroll events that will actually be generated + const left=Math.round(scrollableArea.width/2 - pos[0]); + const top=Math.round(scrollableArea.height/2 - pos[1]); + if (Math.abs(minskyCanvasContainer.scrollLeft-left)>=1 || Math.abs(minskyCanvasContainer.scrollTop-top)>=1) + ++moveOnScroll; + minskyCanvasContainer.scrollLeft=left; + minskyCanvasContainer.scrollTop=top; }; this.cmService.resetScroll(); this.zone.runOutsideAngular(() => { if (this.electronService.isElectron) { const handleScroll = async (scrollTop: number, scrollLeft: number) => { + const scrollableArea = this.windowUtilityService.getScrollableArea(); const posX = scrollableArea.width / 2 - scrollLeft; const posY = scrollableArea.height / 2 - scrollTop; if (!moveOnScroll) @@ -94,15 +103,22 @@ export class WiringComponent implements OnInit, OnDestroy { --moveOnScroll; }; + let rescaleTimer: any; minskyCanvasContainer.addEventListener('scroll', async () => { + // once scrolling stops, resize the scrollable area to fit the contents + if (!moveOnScroll) { + clearTimeout(rescaleTimer); + rescaleTimer=setTimeout(()=>this.cmService.resetScroll(),500); + } await handleScroll( minskyCanvasContainer.scrollTop, minskyCanvasContainer.scrollLeft ); }); minskyCanvasContainer.addEventListener('RESET_ZOOM', async () => { - minskyCanvasContainer.scrollTop=scrollableArea.width / 2; - minskyCanvasContainer.scrollLeft=scrollableArea.height / 2; + const scrollableArea = this.windowUtilityService.getScrollableArea(); + minskyCanvasContainer.scrollTop=scrollableArea.height / 2; + minskyCanvasContainer.scrollLeft=scrollableArea.width / 2; }); minskyCanvasContainer.addEventListener('RESET_SCROLL', async () => { this.cmService.resetScroll(); diff --git a/model/canvas.h b/model/canvas.h index e4555547f..b3703b927 100644 --- a/model/canvas.h +++ b/model/canvas.h @@ -131,6 +131,14 @@ namespace minsky requestRedraw(); } + /// bounds {x0,y0,x1,y1} of the items on the canvas, in window + /// coordinates (ie including the current pan position) + std::vector contentBounds() const { + double x0,y0,x1,y1; + model->contentBounds(x0,y0,x1,y1); + return {x0,y0,x1,y1}; + } + std::vector position() const override { return {model->x(), model->y()}; } From 46a75b6be5bda3106b82ef2d60ad4575aff8e421 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Thu, 19 Nov 2026 23:27:37 +0000 Subject: [PATCH 02/14] Keep current pan within resized scrollable area (#782) Co-Authored-By: Claude Sonnet 5.5 --- .../src/lib/services/WindowUtility/window-utility.service.ts | 4 +++- gui-js/libs/shared/src/lib/backend/minsky.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts b/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts index 7c2e0aaa3..2c2653616 100644 --- a/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts +++ b/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts @@ -69,7 +69,9 @@ export class WindowUtilityService { // contents' extent relative to the unpanned origin const extent = Math.max(Math.abs(b0 - p), Math.abs(b1 - p), 0); const half = this.SCROLLABLE_AREA_FACTOR * extent; - return Math.ceil(Math.max(drawable + 2 * half, 2 * drawable)); + // also keep the current pan within the scroll range: + // 0 <= W/2 - p <= W - drawable + return Math.ceil(Math.max(drawable + 2 * half, 2 * drawable, 2 * p, 2 * (drawable - p))); }; const w = size(bounds[0], bounds[2], pos[0], this.drawableWidth); const h = size(bounds[1], bounds[3], pos[1], this.drawableHeight); diff --git a/gui-js/libs/shared/src/lib/backend/minsky.ts b/gui-js/libs/shared/src/lib/backend/minsky.ts index bb8f22453..3922a482e 100644 --- a/gui-js/libs/shared/src/lib/backend/minsky.ts +++ b/gui-js/libs/shared/src/lib/backend/minsky.ts @@ -436,6 +436,7 @@ export class Canvas extends RenderNativeWindow { async applyDefaultPlotOptions(): Promise {return this.$callMethod('applyDefaultPlotOptions');} async clickType(...args: string[]): Promise {return this.$callMethod('clickType',...args);} async closestInPort(a1: number,a2: number): Promise {return this.$callMethod('closestInPort',a1,a2);} + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async copyAllFlowVars(): Promise {return this.$callMethod('copyAllFlowVars');} async copyAllStockVars(): Promise {return this.$callMethod('copyAllStockVars');} From 70cc3858998a026d38a011b056a2ee967bcdb8b8 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Thu, 19 Nov 2026 23:28:19 +0000 Subject: [PATCH 03/14] Discard stale scroll reset if user scrolled meanwhile (#782) Co-Authored-By: Claude Sonnet 5.5 --- .../libs/ui-components/src/lib/wiring/wiring.component.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index 0bf20d852..f5e38aa19 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -63,6 +63,7 @@ export class WiringComponent implements OnInit, OnDestroy { private setupEventListenersForCanvas(minskyCanvasContainer: HTMLElement) { const minskyCanvasElement = document.getElementById('main-minsky-canvas') as HTMLElement; var moveOnScroll=0; // avoid moving when programmatically setting scroll bars + var scrollGeneration=0; // incremented on each user scroll, to detect stale resets const tabElements = document.getElementsByClassName('tab'); for(let i = 0; i < tabElements.length; i++) { @@ -75,11 +76,15 @@ export class WiringComponent implements OnInit, OnDestroy { } this.cmService.resetScroll=async ()=>{ + const generation=scrollGeneration; var pos= await this.electronService.currentTabPosition(); try { const bounds=await this.electronService.minsky.canvas.contentBounds(); this.windowUtilityService.updateScrollableArea(bounds,pos); } catch (e) {console.error(e);} + // user scrolled while awaiting: discard this stale reset, the + // debounce from the latest scroll will perform a fresh one + if (generation!==scrollGeneration) return; const scrollableArea = this.windowUtilityService.getScrollableArea(); // only count scroll events that will actually be generated const left=Math.round(scrollableArea.width/2 - pos[0]); @@ -107,6 +112,7 @@ export class WiringComponent implements OnInit, OnDestroy { minskyCanvasContainer.addEventListener('scroll', async () => { // once scrolling stops, resize the scrollable area to fit the contents if (!moveOnScroll) { + ++scrollGeneration; clearTimeout(rescaleTimer); rescaleTimer=setTimeout(()=>this.cmService.resetScroll(),500); } From 2fd35a5850012eaf45e95a4ba5379c73579f3133 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Thu, 19 Nov 2026 23:29:01 +0000 Subject: [PATCH 04/14] Defer scrollable area resize while shift-dragging (#782) Co-Authored-By: Claude Sonnet 5.5 --- .../ui-components/src/lib/wiring/wiring.component.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index f5e38aa19..482fa0b66 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -114,7 +114,15 @@ export class WiringComponent implements OnInit, OnDestroy { if (!moveOnScroll) { ++scrollGeneration; clearTimeout(rescaleTimer); - rescaleTimer=setTimeout(()=>this.cmService.resetScroll(),500); + const rescale=()=>{ + // resizing mid-drag would shift the scroll baseline the drag is relative to, + // so wait until the drag ends + if (this.cmService.drag) + rescaleTimer=setTimeout(rescale,500); + else + this.cmService.resetScroll(); + }; + rescaleTimer=setTimeout(rescale,500); } await handleScroll( minskyCanvasContainer.scrollTop, From 920e3a02feaf49f7996db3fdc4828b1369042637 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Thu, 19 Nov 2026 23:35:33 +0000 Subject: [PATCH 05/14] Check for stale scroll reset before resizing scrollable area (#782) Co-Authored-By: Claude Sonnet 5.5 --- .../ui-components/src/lib/wiring/wiring.component.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index 482fa0b66..406b8285c 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -78,13 +78,14 @@ export class WiringComponent implements OnInit, OnDestroy { this.cmService.resetScroll=async ()=>{ const generation=scrollGeneration; var pos= await this.electronService.currentTabPosition(); + let bounds: number[]; try { - const bounds=await this.electronService.minsky.canvas.contentBounds(); - this.windowUtilityService.updateScrollableArea(bounds,pos); + bounds=await this.electronService.minsky.canvas.contentBounds(); } catch (e) {console.error(e);} - // user scrolled while awaiting: discard this stale reset, the - // debounce from the latest scroll will perform a fresh one + // user scrolled while awaiting: discard this stale reset (including the + // resize), the debounce from the latest scroll will perform a fresh one if (generation!==scrollGeneration) return; + if (bounds) this.windowUtilityService.updateScrollableArea(bounds,pos); const scrollableArea = this.windowUtilityService.getScrollableArea(); // only count scroll events that will actually be generated const left=Math.round(scrollableArea.width/2 - pos[0]); From b40d94586dd2cb0dbd0d09859d2e564b5266ec36 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Thu, 19 Nov 2026 23:52:23 +0000 Subject: [PATCH 06/14] Don't scroll on tab switch; size scrollbars after tab renders (#782) Programmatic scrolling/resizing is now suppressed from being treated as user panning, which was resetting the newly selected tab's position. Tab switching no longer centres the scrollbars; resetScroll restores the tab's own pan position once rendered. Content bounds are taken from the current tab via a new RenderNativeWindow::contentBounds() (empty by default, overridden by Canvas); tabs without bounds use a large area. Co-Authored-By: Claude Sonnet 5.5 --- .../apps/minsky-web/src/app/app.component.ts | 8 ++--- .../WindowUtility/window-utility.service.ts | 7 +++- gui-js/libs/shared/src/lib/backend/minsky.ts | 1 + .../src/lib/wiring/wiring.component.ts | 32 +++++++++---------- model/canvas.h | 2 +- model/renderNativeWindow.h | 3 ++ 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/gui-js/apps/minsky-web/src/app/app.component.ts b/gui-js/apps/minsky-web/src/app/app.component.ts index 939352990..030a657d9 100644 --- a/gui-js/apps/minsky-web/src/app/app.component.ts +++ b/gui-js/apps/minsky-web/src/app/app.component.ts @@ -180,11 +180,9 @@ export class AppComponent implements OnInit, DoCheck { await this.windowUtilityService.reInitialize(); const payload = { newTab: tab }; await this.electronService.invoke(events.CHANGE_MAIN_TAB, payload); - var container=this.windowUtilityService.getMinskyContainerElement(); - const scrollableArea=this.windowUtilityService.getScrollableArea(); - container.scrollTop=scrollableArea.height / 2; - container.scrollLeft=scrollableArea.width / 2; - this.cmService.resetScroll(); + // restore the new tab's own pan position (without moving it), and + // size the scrollbars now that the tab has rendered + await this.cmService.resetScroll(); }, 1); } } diff --git a/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts b/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts index 2c2653616..0268e7cda 100644 --- a/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts +++ b/gui-js/libs/core/src/lib/services/WindowUtility/window-utility.service.ts @@ -17,6 +17,8 @@ export class WindowUtilityService { private mainWindowId = 1; // scrollable area is this multiple of the extent of the canvas contents SCROLLABLE_AREA_FACTOR = 1.5; + // scrollable area as a multiple of the drawable area, for tabs that cannot report their content extents + UNKNOWN_EXTENT_FACTOR = 100; constructor(private electronService: ElectronService) { } @@ -64,7 +66,10 @@ export class WindowUtilityService { * @returns true if the scrollable area changed */ public updateScrollableArea(bounds: number[], pos: number[]): boolean { - if (!this.minskyCanvasElement || !bounds || bounds.length < 4) return false; + if (!this.minskyCanvasElement) return false; + if (!bounds || bounds.length < 4) + // content extent unknown for this tab: use a generously sized area + bounds = [0, 0, this.drawableWidth * this.UNKNOWN_EXTENT_FACTOR / 2, this.drawableHeight * this.UNKNOWN_EXTENT_FACTOR / 2]; const size = (b0: number, b1: number, p: number, drawable: number) => { // contents' extent relative to the unpanned origin const extent = Math.max(Math.abs(b0 - p), Math.abs(b1 - p), 0); diff --git a/gui-js/libs/shared/src/lib/backend/minsky.ts b/gui-js/libs/shared/src/lib/backend/minsky.ts index 3922a482e..ec5791a3f 100644 --- a/gui-js/libs/shared/src/lib/backend/minsky.ts +++ b/gui-js/libs/shared/src/lib/backend/minsky.ts @@ -168,6 +168,7 @@ export class RenderNativeWindow extends EventInterface { super(prefix.$prefix()) this.backgroundColour=new ecolab__cairo__Colour(this.$prefix()+'.backgroundColour'); } + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async draw(): Promise {return this.$callMethod('draw');} async frameArgs(): Promise {return this.$callMethod('frameArgs');} diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index 406b8285c..465e715b7 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -10,7 +10,7 @@ import { ElectronService, WindowUtilityService, } from '@minsky/core'; -import { events, MainRenderingTabs, minsky } from '@minsky/shared'; +import { events, MainRenderingTabs, minsky, RenderNativeWindow } from '@minsky/shared'; import { fromEvent, Observable, Subject, takeUntil } from 'rxjs'; import { sampleTime } from 'rxjs/operators'; import { AvailableOperationsComponent } from './available-operations/available-operations.component'; @@ -62,7 +62,7 @@ export class WiringComponent implements OnInit, OnDestroy { private setupEventListenersForCanvas(minskyCanvasContainer: HTMLElement) { const minskyCanvasElement = document.getElementById('main-minsky-canvas') as HTMLElement; - var moveOnScroll=0; // avoid moving when programmatically setting scroll bars + var suppressScroll=false; // ignore scroll events caused by programmatically setting scroll bars or resizing var scrollGeneration=0; // incremented on each user scroll, to detect stale resets const tabElements = document.getElementsByClassName('tab'); @@ -80,20 +80,22 @@ export class WiringComponent implements OnInit, OnDestroy { var pos= await this.electronService.currentTabPosition(); let bounds: number[]; try { - bounds=await this.electronService.minsky.canvas.contentBounds(); + // bounds of the currently displayed tab (empty if the tab cannot report them) + bounds=await new RenderNativeWindow(this.cmService.currentTab).contentBounds(); } catch (e) {console.error(e);} // user scrolled while awaiting: discard this stale reset (including the // resize), the debounce from the latest scroll will perform a fresh one if (generation!==scrollGeneration) return; - if (bounds) this.windowUtilityService.updateScrollableArea(bounds,pos); + // resizing or setting the scroll position generates scroll events, + // which must not be interpreted as the user panning + suppressScroll=true; + this.windowUtilityService.updateScrollableArea(bounds,pos); const scrollableArea = this.windowUtilityService.getScrollableArea(); - // only count scroll events that will actually be generated - const left=Math.round(scrollableArea.width/2 - pos[0]); - const top=Math.round(scrollableArea.height/2 - pos[1]); - if (Math.abs(minskyCanvasContainer.scrollLeft-left)>=1 || Math.abs(minskyCanvasContainer.scrollTop-top)>=1) - ++moveOnScroll; - minskyCanvasContainer.scrollLeft=left; - minskyCanvasContainer.scrollTop=top; + minskyCanvasContainer.scrollLeft=Math.round(scrollableArea.width/2 - pos[0]); + minskyCanvasContainer.scrollTop=Math.round(scrollableArea.height/2 - pos[1]); + // scroll events are delivered before the next animation frame callbacks + await new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(()=>resolve()))); + suppressScroll=false; }; this.cmService.resetScroll(); @@ -103,16 +105,14 @@ export class WiringComponent implements OnInit, OnDestroy { const scrollableArea = this.windowUtilityService.getScrollableArea(); const posX = scrollableArea.width / 2 - scrollLeft; const posY = scrollableArea.height / 2 - scrollTop; - if (!moveOnScroll) - await this.electronService.currentTabMoveTo(posX,posY); - else - --moveOnScroll; + await this.electronService.currentTabMoveTo(posX,posY); }; let rescaleTimer: any; minskyCanvasContainer.addEventListener('scroll', async () => { + if (suppressScroll) return; // once scrolling stops, resize the scrollable area to fit the contents - if (!moveOnScroll) { + { ++scrollGeneration; clearTimeout(rescaleTimer); const rescale=()=>{ diff --git a/model/canvas.h b/model/canvas.h index b3703b927..b58a351ae 100644 --- a/model/canvas.h +++ b/model/canvas.h @@ -133,7 +133,7 @@ namespace minsky /// bounds {x0,y0,x1,y1} of the items on the canvas, in window /// coordinates (ie including the current pan position) - std::vector contentBounds() const { + std::vector contentBounds() const override { double x0,y0,x1,y1; model->contentBounds(x0,y0,x1,y1); return {x0,y0,x1,y1}; diff --git a/model/renderNativeWindow.h b/model/renderNativeWindow.h index ca13fbe2d..69184ddec 100644 --- a/model/renderNativeWindow.h +++ b/model/renderNativeWindow.h @@ -75,6 +75,9 @@ namespace minsky static double scaleFactor(); /// return whether this window has scrollbars (needed for MacOSX). virtual bool hasScrollBars() const {return false;} + /// bounds {x0,y0,x1,y1} of the rendered content in window + /// coordinates, used to size the scrollable area. Empty if unknown. + virtual std::vector contentBounds() const {return {};} private: CLASSDESC_ACCESS(RenderNativeWindow); From 00b75921d83812338c892f923d94e0cd1863cf79 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 00:35:32 +0000 Subject: [PATCH 07/14] Prevent scroll events leaking between tabs (#782) Scroll handling now addresses the tab explicitly rather than whichever tab is current when the IPC lands, and scroll events are ignored while a tab switch is in progress. Co-Authored-By: Claude Sonnet 5.5 --- gui-js/apps/minsky-web/src/app/app.component.ts | 7 ++++++- .../communication/communication.service.ts | 3 ++- .../src/lib/wiring/wiring.component.ts | 16 ++++++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gui-js/apps/minsky-web/src/app/app.component.ts b/gui-js/apps/minsky-web/src/app/app.component.ts index 030a657d9..fbb3b5535 100644 --- a/gui-js/apps/minsky-web/src/app/app.component.ts +++ b/gui-js/apps/minsky-web/src/app/app.component.ts @@ -174,6 +174,7 @@ export class AppComponent implements OnInit, DoCheck { this.router.navigate(['wiring']); if (this.electronService.isElectron) { + this.cmService.tabSwitching = true; this.cmService.currentTab = tab; setTimeout(async ()=> { @@ -182,7 +183,11 @@ export class AppComponent implements OnInit, DoCheck { await this.electronService.invoke(events.CHANGE_MAIN_TAB, payload); // restore the new tab's own pan position (without moving it), and // size the scrollbars now that the tab has rendered - await this.cmService.resetScroll(); + try { + await this.cmService.resetScroll(); + } finally { + this.cmService.tabSwitching = false; + } }, 1); } } diff --git a/gui-js/libs/core/src/lib/services/communication/communication.service.ts b/gui-js/libs/core/src/lib/services/communication/communication.service.ts index d06661142..3f971261e 100644 --- a/gui-js/libs/core/src/lib/services/communication/communication.service.ts +++ b/gui-js/libs/core/src/lib/services/communication/communication.service.ts @@ -70,7 +70,8 @@ export class CommunicationService { private dialogRef: MatDialogRef = null; availableOperations = null; - resetScroll = () => { }; // callback to reset canvas scrollbars + tabSwitching = false; // true while the main tab is being changed: scroll events must not pan the tab + resetScroll: () => Promise | void = () => { }; // callback to reset canvas scrollbars constructor( // private socket: Socket, diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index 465e715b7..901c8eb78 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -10,7 +10,7 @@ import { ElectronService, WindowUtilityService, } from '@minsky/core'; -import { events, MainRenderingTabs, minsky, RenderNativeWindow } from '@minsky/shared'; +import { events, EventInterface, MainRenderingTabs, minsky, RenderNativeWindow } from '@minsky/shared'; import { fromEvent, Observable, Subject, takeUntil } from 'rxjs'; import { sampleTime } from 'rxjs/operators'; import { AvailableOperationsComponent } from './available-operations/available-operations.component'; @@ -77,15 +77,16 @@ export class WiringComponent implements OnInit, OnDestroy { this.cmService.resetScroll=async ()=>{ const generation=scrollGeneration; - var pos= await this.electronService.currentTabPosition(); + const tab=this.cmService.currentTab; + var pos= await new EventInterface(tab).position(); let bounds: number[]; try { // bounds of the currently displayed tab (empty if the tab cannot report them) - bounds=await new RenderNativeWindow(this.cmService.currentTab).contentBounds(); + bounds=await new RenderNativeWindow(tab).contentBounds(); } catch (e) {console.error(e);} // user scrolled while awaiting: discard this stale reset (including the // resize), the debounce from the latest scroll will perform a fresh one - if (generation!==scrollGeneration) return; + if (generation!==scrollGeneration || tab!==this.cmService.currentTab) return; // resizing or setting the scroll position generates scroll events, // which must not be interpreted as the user panning suppressScroll=true; @@ -102,15 +103,18 @@ export class WiringComponent implements OnInit, OnDestroy { this.zone.runOutsideAngular(() => { if (this.electronService.isElectron) { const handleScroll = async (scrollTop: number, scrollLeft: number) => { + // address the tab explicitly, so a move still in flight when the tab + // is switched cannot be applied to the newly selected tab + const tab=this.cmService.currentTab; const scrollableArea = this.windowUtilityService.getScrollableArea(); const posX = scrollableArea.width / 2 - scrollLeft; const posY = scrollableArea.height / 2 - scrollTop; - await this.electronService.currentTabMoveTo(posX,posY); + await new EventInterface(tab).moveTo(posX,posY); }; let rescaleTimer: any; minskyCanvasContainer.addEventListener('scroll', async () => { - if (suppressScroll) return; + if (suppressScroll || this.cmService.tabSwitching) return; // once scrolling stops, resize the scrollable area to fit the contents { ++scrollGeneration; From 1118fd8d1098cd3e09e6bb14979a1e25e09e04c0 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 11:56:29 +1100 Subject: [PATCH 08/14] chore: update minsky.ts --- gui-js/libs/shared/src/lib/backend/minsky.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gui-js/libs/shared/src/lib/backend/minsky.ts b/gui-js/libs/shared/src/lib/backend/minsky.ts index ec5791a3f..54f64d121 100644 --- a/gui-js/libs/shared/src/lib/backend/minsky.ts +++ b/gui-js/libs/shared/src/lib/backend/minsky.ts @@ -642,6 +642,7 @@ export class EquationDisplay extends RenderNativeWindow { this.item=new Item(this.$prefix()+'.item'); this.wire=new Wire(this.$prefix()+'.wire'); } + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async draw(): Promise {return this.$callMethod('draw');} @@ -694,6 +695,7 @@ export class FontDisplay extends CppClass { this.item=new Item(this.$prefix()+'.item'); this.wire=new Wire(this.$prefix()+'.wire'); } + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async draw(): Promise {return this.$callMethod('draw');} @@ -928,6 +930,7 @@ export class GodleyTableWindow extends CppClass { async colX(a1: number): Promise {return this.$callMethod('colX',a1);} async colXZoomed(a1: number): Promise {return this.$callMethod('colXZoomed',a1);} async columnButtonsOffset(...args: number[]): Promise {return this.$callMethod('columnButtonsOffset',...args);} + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async copy(): Promise {return this.$callMethod('copy');} async cut(): Promise {return this.$callMethod('cut');} @@ -1493,6 +1496,7 @@ export class PhillipsDiagram extends RenderNativeWindow { this.wire=new Wire(this.$prefix()+'.wire'); } async clear(): Promise {return this.$callMethod('clear');} + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async draw(): Promise {return this.$callMethod('draw');} @@ -1607,6 +1611,7 @@ export class PlotWidget extends Item { async clickType(a1: number,a2: number): Promise {return this.$callMethod('clickType',a1,a2);} async connectVar(a1: VariableValue,a2: number): Promise {return this.$callMethod('connectVar',a1,a2);} async contains(a1: number,a2: number): Promise {return this.$callMethod('contains',a1,a2);} + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disconnectAllVars(): Promise {return this.$callMethod('disconnectAllVars');} @@ -1872,6 +1877,7 @@ export class RavelPopup extends CppClass { this.item=new Item(this.$prefix()+'.item'); this.wire=new Wire(this.$prefix()+'.wire'); } + async contentBounds(): Promise {return this.$callMethod('contentBounds');} async controlMouseDown(a1: number,a2: number): Promise {return this.$callMethod('controlMouseDown',a1,a2);} async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async draw(): Promise {return this.$callMethod('draw');} From 28d9d27654520cd278174ccb5821f16dd28879e8 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 00:57:22 +0000 Subject: [PATCH 09/14] Clear pending scrollable area resize timer on destroy (#782) Co-Authored-By: Claude Sonnet 5.5 --- .../ui-components/src/lib/wiring/wiring.component.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts index 901c8eb78..2012a17d6 100644 --- a/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts +++ b/gui-js/libs/ui-components/src/lib/wiring/wiring.component.ts @@ -35,6 +35,7 @@ export class WiringComponent implements OnInit, OnDestroy { wiringTab = MainRenderingTabs.canvas; destroy$ = new Subject<{}>(); + private rescaleTimer: ReturnType; // pending scrollable area resize constructor( public cmService: CommunicationService, @@ -112,22 +113,21 @@ export class WiringComponent implements OnInit, OnDestroy { await new EventInterface(tab).moveTo(posX,posY); }; - let rescaleTimer: any; minskyCanvasContainer.addEventListener('scroll', async () => { if (suppressScroll || this.cmService.tabSwitching) return; // once scrolling stops, resize the scrollable area to fit the contents { ++scrollGeneration; - clearTimeout(rescaleTimer); + clearTimeout(this.rescaleTimer); const rescale=()=>{ // resizing mid-drag would shift the scroll baseline the drag is relative to, // so wait until the drag ends if (this.cmService.drag) - rescaleTimer=setTimeout(rescale,500); + this.rescaleTimer=setTimeout(rescale,500); else this.cmService.resetScroll(); }; - rescaleTimer=setTimeout(rescale,500); + this.rescaleTimer=setTimeout(rescale,500); } await handleScroll( minskyCanvasContainer.scrollTop, @@ -233,6 +233,7 @@ export class WiringComponent implements OnInit, OnDestroy { } ngOnDestroy() { + clearTimeout(this.rescaleTimer); this.destroy$.next(undefined); this.destroy$.complete(); } From 1f978ba718ad6a2ffced1b18fbbdb3d582d19fc3 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 01:21:55 +0000 Subject: [PATCH 10/14] Inject shared WindowUtilityService into AppComponent (#782) AppComponent constructed a private instance, so reInitialize() on tab change reset the canvas size independently of the instance used by the wiring component's resetScroll(). Co-Authored-By: Claude Sonnet 5.5 --- gui-js/apps/minsky-web/src/app/app.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui-js/apps/minsky-web/src/app/app.component.ts b/gui-js/apps/minsky-web/src/app/app.component.ts index fbb3b5535..88517ddeb 100644 --- a/gui-js/apps/minsky-web/src/app/app.component.ts +++ b/gui-js/apps/minsky-web/src/app/app.component.ts @@ -26,7 +26,6 @@ export class AppComponent implements OnInit, DoCheck { loading = true; publicationTabs = []; - private windowUtilityService: WindowUtilityService; private resizeTimeout; constructor( private electronService: ElectronService, @@ -34,8 +33,8 @@ export class AppComponent implements OnInit, DoCheck { private translate: TranslateService, private cdRef: ChangeDetectorRef, public router: Router, + private windowUtilityService: WindowUtilityService, ) { - this.windowUtilityService=new WindowUtilityService(electronService); this.translate.setDefaultLang('en'); } From 2ac9719f1a4390e32a6112bcb8eb7cfbce98135b Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 01:23:11 +0000 Subject: [PATCH 11/14] Always clear tabSwitching if tab change steps fail (#782) Co-Authored-By: Claude Sonnet 5.5 --- gui-js/apps/minsky-web/src/app/app.component.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gui-js/apps/minsky-web/src/app/app.component.ts b/gui-js/apps/minsky-web/src/app/app.component.ts index 88517ddeb..70d025e69 100644 --- a/gui-js/apps/minsky-web/src/app/app.component.ts +++ b/gui-js/apps/minsky-web/src/app/app.component.ts @@ -177,14 +177,15 @@ export class AppComponent implements OnInit, DoCheck { this.cmService.currentTab = tab; setTimeout(async ()=> { - await this.windowUtilityService.reInitialize(); - const payload = { newTab: tab }; - await this.electronService.invoke(events.CHANGE_MAIN_TAB, payload); - // restore the new tab's own pan position (without moving it), and - // size the scrollbars now that the tab has rendered try { + await this.windowUtilityService.reInitialize(); + const payload = { newTab: tab }; + await this.electronService.invoke(events.CHANGE_MAIN_TAB, payload); + // restore the new tab's own pan position (without moving it), and + // size the scrollbars now that the tab has rendered await this.cmService.resetScroll(); } finally { + // always re-enable scrolling, even if a step above failed this.cmService.tabSwitching = false; } }, 1); From 77716c97b053edaf290e73f9d0259165b1674b81 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 01:33:52 +0000 Subject: [PATCH 12/14] Report content bounds for equation, Phillips and publication tabs (#782) Override RenderNativeWindow::contentBounds() so the scrollable area for these tabs is also 1.5x the extent of their contents, rather than the large fixed fallback. Co-Authored-By: Claude Sonnet 5.5 --- model/equationDisplay.h | 4 ++++ model/phillipsDiagram.cc | 15 +++++++++++++++ model/phillipsDiagram.h | 1 + model/pubTab.cc | 19 +++++++++++++++++++ model/pubTab.h | 1 + 5 files changed, 40 insertions(+) diff --git a/model/equationDisplay.h b/model/equationDisplay.h index 6d288059b..f7b3b2da0 100644 --- a/model/equationDisplay.h +++ b/model/equationDisplay.h @@ -41,6 +41,10 @@ namespace minsky EquationDisplay(const EquationDisplay&)=default; void requestRedraw() {if (surface.get()) surface->requestRedraw();} bool hasScrollBars() const override {return true;} + std::vector contentBounds() const override { + // equations are rendered at the pan offset, scaled by the zoom factor + return {offsx, offsy, offsx+m_width*m_zoomFactor, offsy+m_height*m_zoomFactor}; + } }; } diff --git a/model/phillipsDiagram.cc b/model/phillipsDiagram.cc index 565ca0ab2..f97726c7f 100644 --- a/model/phillipsDiagram.cc +++ b/model/phillipsDiagram.cc @@ -122,6 +122,21 @@ namespace minsky return true; } + std::vector PhillipsDiagram::contentBounds() const + { + // stocks are drawn at their own position offset by the pan position (x,y) + if (stocks.empty()) return {x,y,x,y}; + double x0=std::numeric_limits::max(), y0=x0, x1=-x0, y1=-x0; + for (auto& i: stocks) + { + x0=std::min(x0,i.second.left()); + x1=std::max(x1,i.second.right()); + y0=std::min(y0,i.second.top()); + y1=std::max(y1,i.second.bottom()); + } + return {x0+x, y0+y, x1+x, y1+y}; + } + void PhillipsDiagram::init() { decltype(stocks) newStocks; diff --git a/model/phillipsDiagram.h b/model/phillipsDiagram.h index 4c3ceba8d..f202c96d6 100644 --- a/model/phillipsDiagram.h +++ b/model/phillipsDiagram.h @@ -101,6 +101,7 @@ namespace minsky std::vector position() const override {return {x,y};} void startRotatingItem(float x, float y); bool hasScrollBars() const override {return true;} + std::vector contentBounds() const override; }; } diff --git a/model/pubTab.cc b/model/pubTab.cc index 280350282..6b418d059 100644 --- a/model/pubTab.cc +++ b/model/pubTab.cc @@ -174,6 +174,25 @@ namespace minsky return !items.empty() || clickType!=ClickType::outside; } + std::vector PubTab::contentBounds() const + { + // items are drawn at (x,y) within the tab, then scaled by the zoom and translated by the pan offset + double x0=std::numeric_limits::max(), y0=x0, x1=-x0, y1=-x0; + for (auto& i: items) + { + if (!i.itemRef) continue; + // restores item state on destruction, so safe to apply to a const PubTab + const EnsureEditorMode e(const_cast(i)); + const double ix=i.itemRef->x(), iy=i.itemRef->y(); + x0=std::min(x0,i.x+i.itemRef->left()-ix); + x1=std::max(x1,i.x+i.itemRef->right()-ix); + y0=std::min(y0,i.y+i.itemRef->top()-iy); + y1=std::max(y1,i.y+i.itemRef->bottom()-iy); + } + if (x0>x1) return {offsx,offsy,offsx,offsy}; + return {offsx+x0*m_zoomFactor, offsy+y0*m_zoomFactor, offsx+x1*m_zoomFactor, offsy+y1*m_zoomFactor}; + } + PubItem* PubTab::m_getItemAt(float x, float y) { for (auto& i: items) diff --git a/model/pubTab.h b/model/pubTab.h index 416df134b..429155c27 100644 --- a/model/pubTab.h +++ b/model/pubTab.h @@ -87,6 +87,7 @@ namespace minsky void mouseMove(float x, float y) override; bool keyPress(const EventInterface::KeyPressArgs&) override; bool hasScrollBars() const override {return true;} + std::vector contentBounds() const override; }; } From 4b69e4605fdc20437be84d55a070c794fa129187 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 03:41:10 +0000 Subject: [PATCH 13/14] Only the latest tab switch may clear tabSwitching (#782) Co-Authored-By: Claude Sonnet 5.5 --- gui-js/apps/minsky-web/src/app/app.component.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gui-js/apps/minsky-web/src/app/app.component.ts b/gui-js/apps/minsky-web/src/app/app.component.ts index 70d025e69..4adf32dee 100644 --- a/gui-js/apps/minsky-web/src/app/app.component.ts +++ b/gui-js/apps/minsky-web/src/app/app.component.ts @@ -27,6 +27,7 @@ export class AppComponent implements OnInit, DoCheck { loading = true; publicationTabs = []; private resizeTimeout; + private tabSwitchGeneration=0; // identifies the most recent main tab switch constructor( private electronService: ElectronService, private cmService: CommunicationService, @@ -173,6 +174,7 @@ export class AppComponent implements OnInit, DoCheck { this.router.navigate(['wiring']); if (this.electronService.isElectron) { + const generation=++this.tabSwitchGeneration; this.cmService.tabSwitching = true; this.cmService.currentTab = tab; @@ -185,8 +187,10 @@ export class AppComponent implements OnInit, DoCheck { // size the scrollbars now that the tab has rendered await this.cmService.resetScroll(); } finally { - // always re-enable scrolling, even if a step above failed - this.cmService.tabSwitching = false; + // re-enable scrolling, even if a step above failed, but only if no + // later switch has started and is still in progress + if (generation===this.tabSwitchGeneration) + this.cmService.tabSwitching = false; } }, 1); } From daf684f33144595406fe55a18eff103cffa13966 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Fri, 20 Nov 2026 04:09:27 +0000 Subject: [PATCH 14/14] Include flow handles in Phillips diagram content bounds (#782) Co-Authored-By: Claude Sonnet 5.5 --- model/phillipsDiagram.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/model/phillipsDiagram.cc b/model/phillipsDiagram.cc index f97726c7f..458f18e0a 100644 --- a/model/phillipsDiagram.cc +++ b/model/phillipsDiagram.cc @@ -124,8 +124,7 @@ namespace minsky std::vector PhillipsDiagram::contentBounds() const { - // stocks are drawn at their own position offset by the pan position (x,y) - if (stocks.empty()) return {x,y,x,y}; + // stocks and flow handles are drawn at their own positions, offset by the pan position (x,y) double x0=std::numeric_limits::max(), y0=x0, x1=-x0, y1=-x0; for (auto& i: stocks) { @@ -134,6 +133,20 @@ namespace minsky y0=std::min(y0,i.second.top()); y1=std::max(y1,i.second.bottom()); } + for (auto& i: flows) + { + if (!i.second.from() || !i.second.to()) continue; + // end points and intermediate control points + auto c=i.second.coords(); + for (size_t j=0; j+1(x0,c[j]); + x1=std::max(x1,c[j]); + y0=std::min(y0,c[j+1]); + y1=std::max(y1,c[j+1]); + } + } + if (x0>x1) return {x,y,x,y}; // nothing to display return {x0+x, y0+y, x1+x, y1+y}; }