Skip to content

Commit

Permalink
fix(calc): Improve zoom view-jumping
Browse files Browse the repository at this point in the history
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 d6f375c)
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
- I haven't confirmed that it works with different app.dpiScale

Signed-off-by: Skyler Grey <[email protected]>
Change-Id: I7127d8f0a3156ed9dfb04bdd5fb801c318531269
  • Loading branch information
Minion3665 committed Jan 23, 2025
1 parent dd556ff commit 2053685
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions browser/src/layer/tile/CanvasTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)).multiplyBy(app.dpiScale);
} 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,
};
},

Expand Down

0 comments on commit 2053685

Please sign in to comment.