From d16bb2c8318dfd5a6b732914a7c9e85d1ac4eea3 Mon Sep 17 00:00:00 2001 From: will wade Date: Wed, 29 Apr 2026 17:24:24 +0100 Subject: [PATCH 1/3] fix to not add buttons all the time --- src/core/treeStructure.ts | 16 ++++++++++++++++ src/processors/gridsetProcessor.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/treeStructure.ts b/src/core/treeStructure.ts index 18ebe7d..955fff7 100644 --- a/src/core/treeStructure.ts +++ b/src/core/treeStructure.ts @@ -487,6 +487,22 @@ export class AACPage { this._pendingMutations.push({ type: 'addButton', button }); } + /** + * Internal load-path button push: adds a button to the page WITHOUT recording a mutation. + * Used by processors during loadIntoTree so the loaded baseline isn't treated as user changes. + * Not part of the public API — consumers should always use addButton. + */ + _loadButton(button: AACButton): void { + this.buttons.push(button); + + /** + * Discard all recorded mutations on this page. + * Useful as an escape hatch after loadIntoTree if the consumer wants a clean baseline. + */ + clearMutations(): void { + this._pendingMutations = []; + } + /** * Get the list of pending mutations for this page (read-only) */ diff --git a/src/processors/gridsetProcessor.ts b/src/processors/gridsetProcessor.ts index 0566018..bde3ee2 100644 --- a/src/processors/gridsetProcessor.ts +++ b/src/processors/gridsetProcessor.ts @@ -1749,8 +1749,8 @@ class GridsetProcessor extends BaseProcessor { }, }); - // Add button to page - page.addButton(button); + // Add button to page (load path: do not record as a user mutation) + page._loadButton(button); // Place button in grid layout (handle colspan/rowspan) for (let r = cellY; r < cellY + rowSpan && r < maxRows; r++) { From b0870ff2bdaa27c43510da324fa3546b0bb5f5c4 Mon Sep 17 00:00:00 2001 From: will wade Date: Wed, 29 Apr 2026 19:08:15 +0100 Subject: [PATCH 2/3] fix } --- src/core/treeStructure.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/treeStructure.ts b/src/core/treeStructure.ts index 955fff7..658a90b 100644 --- a/src/core/treeStructure.ts +++ b/src/core/treeStructure.ts @@ -494,6 +494,7 @@ export class AACPage { */ _loadButton(button: AACButton): void { this.buttons.push(button); + } /** * Discard all recorded mutations on this page. From 8bfc6384f440ff42cce55cb7fd92df8862d14f8d Mon Sep 17 00:00:00 2001 From: will wade Date: Wed, 29 Apr 2026 22:18:01 +0100 Subject: [PATCH 3/3] make all use loadpath not add button --- src/processors/applePanelsProcessor.ts | 3 ++- src/processors/astericsGridProcessor.ts | 3 ++- src/processors/dotProcessor.ts | 6 ++++-- src/processors/opmlProcessor.ts | 3 ++- src/processors/snapProcessor.ts | 3 ++- src/processors/touchchatProcessor.ts | 6 +++--- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/processors/applePanelsProcessor.ts b/src/processors/applePanelsProcessor.ts index 67157a0..83591ab 100644 --- a/src/processors/applePanelsProcessor.ts +++ b/src/processors/applePanelsProcessor.ts @@ -366,7 +366,8 @@ class ApplePanelsProcessor extends BaseProcessor { fontWeight: btn.DisplayImageWeight === 'bold' ? 'bold' : 'normal', }, }); - page.addButton(button); + // Load path: do not record as a user mutation + page._loadButton(button); if (btn.Rect) { const rect = this.parseRect(btn.Rect); diff --git a/src/processors/astericsGridProcessor.ts b/src/processors/astericsGridProcessor.ts index 6daee9f..203c518 100644 --- a/src/processors/astericsGridProcessor.ts +++ b/src/processors/astericsGridProcessor.ts @@ -917,7 +917,8 @@ class AstericsGridProcessor extends BaseProcessor { colorConfig, activeColorSchemeDefinition ); - page.addButton(button); + // Load path: do not record as a user mutation + page._loadButton(button); const buttonX = element.x || 0; const buttonY = element.y || 0; diff --git a/src/processors/dotProcessor.ts b/src/processors/dotProcessor.ts index 9d78950..0a033ee 100644 --- a/src/processors/dotProcessor.ts +++ b/src/processors/dotProcessor.ts @@ -166,7 +166,8 @@ class DotProcessor extends BaseProcessor { tree.addPage(page); // Add a self button so single-node graphs yield one button - page.addButton( + // Load path: do not record as a user mutation + page._loadButton( new AACButton({ id: `${node.id}_self`, label: node.label, @@ -191,7 +192,8 @@ class DotProcessor extends BaseProcessor { targetPageId: edge.to, }); - fromPage.addButton(button); + // Load path: do not record as a user mutation + fromPage._loadButton(button); } } diff --git a/src/processors/opmlProcessor.ts b/src/processors/opmlProcessor.ts index 491f06e..7efd5a0 100644 --- a/src/processors/opmlProcessor.ts +++ b/src/processors/opmlProcessor.ts @@ -78,7 +78,8 @@ class OpmlProcessor extends BaseProcessor { message: '', targetPageId: childText.replace(/[^a-zA-Z0-9]/g, '_'), }); - page.addButton(button); + // Load path: do not record as a user mutation + page._loadButton(button); const { page: childPage, childPages: grandChildren } = this.processOutline( child, diff --git a/src/processors/snapProcessor.ts b/src/processors/snapProcessor.ts index 9152c78..5491157 100644 --- a/src/processors/snapProcessor.ts +++ b/src/processors/snapProcessor.ts @@ -705,7 +705,8 @@ class SnapProcessor extends BaseProcessor { // Add to the intended parent page const parentPage = tree.getPage(parentUniqueId); if (parentPage) { - parentPage.addButton(button); + // Load path: do not record as a user mutation + parentPage._loadButton(button); // Add button to grid layout if position data is available const gridPositionStr = String(btnRow.GridPosition || ''); diff --git a/src/processors/touchchatProcessor.ts b/src/processors/touchchatProcessor.ts index c9c1926..8d77d54 100644 --- a/src/processors/touchchatProcessor.ts +++ b/src/processors/touchchatProcessor.ts @@ -406,8 +406,8 @@ class TouchChatProcessor extends BaseProcessor { button.x = absoluteX; button.y = absoluteY; - // Add button to page - page.addButton(button); + // Add button to page (load path: do not record as a user mutation) + page._loadButton(button); // Place button in grid (handle span) for (let r = absoluteY; r < absoluteY + safeSpanY && r < 10; r++) { @@ -518,7 +518,7 @@ class TouchChatProcessor extends BaseProcessor { const page = Object.values(tree.pages).find( (p) => p.id === (numericToRid.get(btnRow.id) || String(btnRow.id)) ); - if (page) page.addButton(button); + if (page) page._loadButton(button); // load path: do not record as a user mutation }); } catch (_e) { // console.log('No direct page buttons found:', e);