virtual-tree-canvas 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-tree-canvas",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "High-performance Canvas2D virtual tree/table widget for very large hierarchical datasets.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -892,11 +892,10 @@ export class TreeViewController {
892
892
  }
893
893
 
894
894
  #rebuildRows() {
895
- const scrollX = this.viewport.scrollX;
896
- const scrollY = this.viewport.scrollY;
895
+ const scrollAnchor = this.#captureScrollAnchor();
897
896
  this.rowModel.rebuild();
898
897
  this.#syncContentSize();
899
- this.viewport.scrollTo(scrollX, scrollY);
898
+ this.#restoreScrollAnchor(scrollAnchor);
900
899
  this.rebuildCount++;
901
900
  }
902
901
 
@@ -1149,14 +1148,33 @@ export class TreeViewController {
1149
1148
  }
1150
1149
 
1151
1150
  #applyWorkerRows(result) {
1152
- const scrollX = this.viewport.scrollX;
1153
- const scrollY = this.viewport.scrollY;
1151
+ const scrollAnchor = this.#captureScrollAnchor();
1154
1152
  this.rowModel.applyRows(result);
1155
1153
  this.#syncContentSize();
1156
- this.viewport.scrollTo(scrollX, scrollY);
1154
+ this.#restoreScrollAnchor(scrollAnchor);
1157
1155
  this.rebuildCount++;
1158
1156
  }
1159
1157
 
1158
+ #captureScrollAnchor() {
1159
+ const scrollX = this.viewport.scrollX;
1160
+ const scrollY = this.viewport.scrollY;
1161
+ const rowIndex = Math.max(0, Math.floor(scrollY / this.rowModel.rowHeight));
1162
+ const row = this.rowModel.getRow(rowIndex);
1163
+ if (!row) return { scrollX, scrollY, nodeId: null, offsetY: 0 };
1164
+ return {
1165
+ scrollX,
1166
+ scrollY,
1167
+ nodeId: row.nodeId,
1168
+ offsetY: Math.max(0, scrollY - row.y),
1169
+ };
1170
+ }
1171
+
1172
+ #restoreScrollAnchor(anchor) {
1173
+ const row = anchor.nodeId ? this.rowModel.getRowById(anchor.nodeId) : null;
1174
+ const scrollY = row ? row.y + anchor.offsetY : anchor.scrollY;
1175
+ this.viewport.scrollTo(anchor.scrollX, scrollY);
1176
+ }
1177
+
1160
1178
  #rebuildInspectorModel(focusPath = '') {
1161
1179
  if (!this.inspector) return;
1162
1180
  const expanded = new Set(this.expansion.model.expanded);