From 9a4af5b9ea54780e63417642781ddc2933002607 Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Wed, 22 Jan 2025 10:11:47 +0000 Subject: [PATCH] fix(calc): Improve zoom view-jumping Previously, we got significant view jumps in calc by virtue of an incorrect center position. To fix this, I've melded together the old formula (from before commit d6f375c501690370e41ceeec18200599bd33490c) with the new formula. I've gated this to calc as the old formula is calc specific. More testing will be needed to determine if there is any jumping in writer/impress. This old formula had some pitfalls, as it was made to deal with zooming from the top left of the screen rather than an arbitrary point. Particularly notably, the old formula doesn't deal with anything that is not on the edge of a cell. Therefore, there is still some view jumping, there's just likely to be less-of-it and it'll be a bit more consistent rather than having huge jumps every time on higher positions. This code still doesn't work in some cases, which I will continue to fix: - It doesn't affect tablets - It doesn't work on my Mac. The symptoms are being *nearly there* but ever-so-slightly off Signed-off-by: Skyler Grey Change-Id: I7127d8f0a3156ed9dfb04bdd5fb801c318531269 --- browser/src/layer/tile/CanvasTileLayer.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/browser/src/layer/tile/CanvasTileLayer.js b/browser/src/layer/tile/CanvasTileLayer.js index 62f7b270dd74b..ea7c4706f20fa 100644 --- a/browser/src/layer/tile/CanvasTileLayer.js +++ b/browser/src/layer/tile/CanvasTileLayer.js @@ -489,14 +489,26 @@ L.TileSectionManager = L.Class.extend({ return { offset: this._offset, topLeft: docTopLeft }; } - const newPaneCenter = new L.Point( - (docTopLeft.x - splitPos.x + (paneSize.x + splitPos.x) * 0.5 / scale), - (docTopLeft.y - splitPos.y + (paneSize.y + splitPos.y) * 0.5 / scale)); + let newCenter; + + const newZoom = this._map.getScaleZoom(scale); + if (this._layer.isCalc()) { + const zoomScaleAbs = this._map.zoomToFactor(newZoom); + + const topLeftCell = this._layer.sheetGeometry.getCellFromPos(docTopLeft, 'corepixels'); + const newTopLeftP = this._layer.sheetGeometry.getCellRect(topLeftCell.x, topLeftCell.y, zoomScaleAbs).getTopLeft(); + newCenter = newTopLeftP.add(paneBounds.getSize().divideBy(2)); + } else { + const newPaneCenter = new L.Point( + (docTopLeft.x - splitPos.x + (paneSize.x + splitPos.x) * 0.5 / scale), + (docTopLeft.y - splitPos.y + (paneSize.y + splitPos.y) * 0.5 / scale)); + newCenter = this._map.rescale(newPaneCenter, this._map.getZoom(), newZoom); + } return { offset: this._offset, - topLeft: docTopLeft.add(this._offset), - center: this._map.rescale(newPaneCenter, this._map.getZoom(), this._map.getScaleZoom(scale)), + topLeft: docTopLeft, + center: newCenter, }; },