Skip to content

Commit 1996803

Browse files
authored
Merge pull request #347 from jonah-iden/jiden/zoomScale-centerAction
added zoomScale property to centerAction to set zoom level when executing the action
2 parents 5a8c6c3 + d6bcefd commit 1996803

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/sprotty-protocol/src/actions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,18 @@ export interface CenterAction extends Action {
463463
elementIds: string[]
464464
animate: boolean
465465
retainZoom: boolean
466+
zoomScale?: number
466467
}
467468
export namespace CenterAction {
468469
export const KIND = 'center';
469470

470-
export function create(elementIds: string[], options: { animate?: boolean, retainZoom?: boolean } = {}): CenterAction {
471+
export function create(elementIds: string[], options: { animate?: boolean, retainZoom?: boolean, zoomScale?: number } = {}): CenterAction {
471472
return {
472473
kind: KIND,
473474
elementIds,
474475
animate: options.animate ?? true,
475-
retainZoom: options.retainZoom ?? false
476+
retainZoom: options.retainZoom ?? false,
477+
zoomScale: options.zoomScale
476478
};
477479
}
478480
}

packages/sprotty/src/features/viewport/center-fit.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export class CenterAction implements Action, ProtocolCenterAction {
4444

4545
constructor(public readonly elementIds: string[],
4646
public readonly animate: boolean = true,
47-
public readonly retainZoom: boolean = false) {
47+
public readonly retainZoom: boolean = false,
48+
public readonly zoomScale?: number) {
4849
}
4950
}
5051

@@ -177,7 +178,12 @@ export class CenterCommand extends BoundsAwareViewportCommand {
177178
if (!Dimension.isValid(model.canvasBounds)) {
178179
return undefined;
179180
}
180-
const zoom = (this.action.retainZoom && isViewport(model)) ? model.zoom : 1;
181+
let zoom = 1;
182+
if (this.action.retainZoom && isViewport(model)) {
183+
zoom = model.zoom;
184+
} else if (this.action.zoomScale) {
185+
zoom = this.action.zoomScale;
186+
}
181187
const c = Bounds.center(bounds);
182188
return {
183189
scroll: {

0 commit comments

Comments
 (0)