refactor(editor): enable forceUpdate by default in viewport apis (#11264)

In this way, all downstream callers can be guaranteed by correct viewport fit result, instead of requiring them to set `forceUpdate: true` param explicitly to them. The resizing optimization is an internal exception.
This commit is contained in:
doodlewind
2025-03-28 10:04:55 +00:00
parent 85daea6fa8
commit ebee11f573
3 changed files with 7 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ export class Viewport {
const newCenterX = initialTopLeftX + width / (2 * this.zoom); const newCenterX = initialTopLeftX + width / (2 * this.zoom);
const newCenterY = initialTopLeftY + height / (2 * this.zoom); const newCenterY = initialTopLeftY + height / (2 * this.zoom);
this.setCenter(newCenterX, newCenterY); this.setCenter(newCenterX, newCenterY, false);
this._width = width; this._width = width;
this._height = height; this._height = height;
this._left = left; this._left = left;
@@ -362,7 +362,7 @@ export class Viewport {
* @param centerY The new y coordinate of the center of the viewport. * @param centerY The new y coordinate of the center of the viewport.
* @param forceUpdate Whether to force complete any pending resize operations before setting the viewport. * @param forceUpdate Whether to force complete any pending resize operations before setting the viewport.
*/ */
setCenter(centerX: number, centerY: number, forceUpdate = false) { setCenter(centerX: number, centerY: number, forceUpdate = true) {
if (forceUpdate && this._isResizing) { if (forceUpdate && this._isResizing) {
this._forceCompleteResize(); this._forceCompleteResize();
} }
@@ -405,7 +405,7 @@ export class Viewport {
newZoom: number, newZoom: number,
newCenter = Vec.toVec(this.center), newCenter = Vec.toVec(this.center),
smooth = false, smooth = false,
forceUpdate = smooth forceUpdate = true
) { ) {
// Force complete any pending resize operations if forceUpdate is true // Force complete any pending resize operations if forceUpdate is true
if (forceUpdate && this._isResizing) { if (forceUpdate && this._isResizing) {
@@ -445,7 +445,7 @@ export class Viewport {
bound: Bound, bound: Bound,
padding: [number, number, number, number] = [0, 0, 0, 0], padding: [number, number, number, number] = [0, 0, 0, 0],
smooth = false, smooth = false,
forceUpdate = smooth forceUpdate = true
) { ) {
let [pt, pr, pb, pl] = padding; let [pt, pr, pb, pl] = padding;
@@ -511,7 +511,7 @@ export class Viewport {
zoom: number, zoom: number,
focusPoint?: IPoint, focusPoint?: IPoint,
wheel = false, wheel = false,
forceUpdate = false forceUpdate = true
) { ) {
if (forceUpdate && this._isResizing) { if (forceUpdate && this._isResizing) {
this._forceCompleteResize(); this._forceCompleteResize();

View File

@@ -90,7 +90,7 @@ export function patchForEdgelessNoteConfig(
]); ]);
const center = Vec.sub(edgelessTitleAnchor, pageTitleAnchor); const center = Vec.sub(edgelessTitleAnchor, pageTitleAnchor);
gfx.viewport.setCenter(center[0], center[1], true); gfx.viewport.setCenter(center[0], center[1]);
gfx.viewport.smoothZoom(0.65, undefined, 15); gfx.viewport.smoothZoom(0.65, undefined, 15);
return true; return true;

View File

@@ -58,8 +58,7 @@ function fitViewport(
viewport.setViewportByBound( viewport.setViewportByBound(
Bound.deserialize(newViewport.xywh), Bound.deserialize(newViewport.xywh),
newViewport.padding, newViewport.padding,
false, false
true
); );
} else { } else {
gfx.fitToScreen({ gfx.fitToScreen({