Skip to content

Commit

Permalink
Update workspace_svg.ts
Browse files Browse the repository at this point in the history
Removed the @internal
  • Loading branch information
SophieNguyen113 authored Sep 22, 2023
1 parent 4a6d439 commit a4067aa
Showing 1 changed file with 49 additions and 49 deletions.
98 changes: 49 additions & 49 deletions core/workspace_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2185,57 +2185,57 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
}

/**
* Scroll the workspace to a specified offset (in pixels), keeping in the
* workspace bounds. See comment on workspaceSvg.scrollX for more detail on
* the meaning of these values.
*
* @param x Target X to scroll to.
* @param y Target Y to scroll to.
* @internal
*/
scroll(x: number, y: number) {
this.hideChaff(/* opt_onlyClosePopups= */ true);

// Keep scrolling within the bounds of the content.
const metrics = this.getMetrics();
// Canvas coordinates (aka scroll coordinates) have inverse directionality
// to workspace coordinates so we have to inverse them.
x = Math.min(x, -metrics.scrollLeft);
y = Math.min(y, -metrics.scrollTop);
const maxXDisplacement = Math.max(
0,
metrics.scrollWidth - metrics.viewWidth,
);
const maxXScroll = metrics.scrollLeft + maxXDisplacement;
const maxYDisplacement = Math.max(
0,
metrics.scrollHeight - metrics.viewHeight,
* Scroll the workspace to a specified offset (in pixels), keeping in the
* workspace bounds. See comment on workspaceSvg.scrollX for more detail on
* the meaning of these values.
*
* @param x Target X to scroll to.
* @param y Target Y to scroll to.
*/
scroll(x: number, y: number) {
this.hideChaff(/* opt_onlyClosePopups= */ true);

// Keep scrolling within the bounds of the content.
const metrics = this.getMetrics();
// Canvas coordinates (aka scroll coordinates) have inverse directionality
// to workspace coordinates so we have to inverse them.
x = Math.min(x, -metrics.scrollLeft);
y = Math.min(y, -metrics.scrollTop);
const maxXDisplacement = Math.max(
0,
metrics.scrollWidth - metrics.viewWidth,
);
const maxXScroll = metrics.scrollLeft + maxXDisplacement;
const maxYDisplacement = Math.max(
0,
metrics.scrollHeight - metrics.viewHeight,
);
const maxYScroll = metrics.scrollTop + maxYDisplacement;
x = Math.max(x, -maxXScroll);
y = Math.max(y, -maxYScroll);
this.scrollX = x;
this.scrollY = y;

if (this.scrollbar) {
// The content position (displacement from the content's top-left to the
// origin) plus the scroll position (displacement from the view's top-left
// to the origin) gives us the distance from the view's top-left to the
// content's top-left. Then we negate this so we get the displacement from
// the content's top-left to the view's top-left, matching the
// directionality of the scrollbars.
this.scrollbar.set(
-(x + metrics.scrollLeft),
-(y + metrics.scrollTop),
false,
);
const maxYScroll = metrics.scrollTop + maxYDisplacement;
x = Math.max(x, -maxXScroll);
y = Math.max(y, -maxYScroll);
this.scrollX = x;
this.scrollY = y;

if (this.scrollbar) {
// The content position (displacement from the content's top-left to the
// origin) plus the scroll position (displacement from the view's top-left
// to the origin) gives us the distance from the view's top-left to the
// content's top-left. Then we negate this so we get the displacement from
// the content's top-left to the view's top-left, matching the
// directionality of the scrollbars.
this.scrollbar.set(
-(x + metrics.scrollLeft),
-(y + metrics.scrollTop),
false,
);
}
// We have to shift the translation so that when the canvas is at 0, 0 the
// workspace origin is not underneath the toolbox.
x += metrics.absoluteLeft;
y += metrics.absoluteTop;
this.translate(x, y);
}
// We have to shift the translation so that when the canvas is at 0, 0 the
// workspace origin is not underneath the toolbox.
x += metrics.absoluteLeft;
y += metrics.absoluteTop;
this.translate(x, y);
}


/**
* Find the block on this workspace with the specified ID.
Expand Down

0 comments on commit a4067aa

Please sign in to comment.