Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions packages/blockly/core/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import {computeAriaLabel, getBeginStackLabel} from './block_aria_composer.js';
import {BlockSvg} from './block_svg.js';
import * as browserEvents from './browser_events.js';
import * as bumpObjects from './bump_objects.js';
import * as css from './css.js';
import * as dialog from './dialog.js';
import * as dropDownDiv from './dropdowndiv.js';
Expand All @@ -33,8 +32,10 @@ import * as renderManagement from './render_management.js';
import * as aria from './utils/aria.js';
import {Verbosity} from './utils/aria.js';
import * as dom from './utils/dom.js';
import {Rect} from './utils/rect.js';
import {Size} from './utils/size.js';
import {Svg} from './utils/svg.js';
import * as svgMath from './utils/svg_math.js';
import * as userAgent from './utils/useragent.js';
import * as WidgetDiv from './widgetdiv.js';
import type {WorkspaceSvg} from './workspace_svg.js';
Expand Down Expand Up @@ -842,26 +843,34 @@ export abstract class FieldInput<T extends InputTypes> extends Field<

/**
* Handles repositioning the WidgetDiv used for input fields when the
* workspace is resized. Will bump the block into the viewport and update the
* position of the text input if necessary.
* workspace is resized. Scrolls this field into view, then updates the
* position of the text input.
*
* @returns True for rendered workspaces, as we never want to hide the widget
* div.
*/
override repositionForWindowResize(): boolean {
const block = this.getSourceBlock()?.getRootBlock();
const block = this.getSourceBlock();
const workspace = this.workspace_;
// This shouldn't be possible. We should never have a WidgetDiv if not using
// rendered blocks.
if (!(block instanceof BlockSvg)) return false;

const bumped = bumpObjects.bumpIntoBounds(
this.workspace_!,
this.workspace_!.getMetricsManager().getViewMetrics(true),
block,
);

if (!bumped) this.resizeEditor_();
this.resizeEditor_();

const element = this.getClickTarget_();
if (!element || !workspace) return true;

const bbox = Rect.from(element.getBoundingClientRect());
const origin = svgMath.screenToWsCoordinates(workspace, bbox.getOrigin());
const scale = workspace.scale;
workspace.scrollBoundsIntoView(
Rect.createFromPoint(
origin,
bbox.getWidth() / scale,
bbox.getHeight() / scale,
),
);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/blockly/core/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ function init(mainWorkspace: WorkspaceSvg) {
// possible.
Tooltip.hide();
mainWorkspace.hideComponents(true);
common.svgResize(mainWorkspace);
dropDownDiv.repositionForWindowResize();
WidgetDiv.repositionForWindowResize();
common.svgResize(mainWorkspace);
bumpObjects.bumpTopObjectsIntoBounds(mainWorkspace);
},
);
Expand Down
9 changes: 6 additions & 3 deletions packages/blockly/core/workspace_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2236,9 +2236,12 @@ export class WorkspaceSvg
*
* @param x Target X to scroll to.
* @param y Target Y to scroll to.
* @param shouldHidePopups Whether to hide popups. Defaults to true.
*/
scroll(x: number, y: number) {
this.hideChaff(/* opt_onlyClosePopups= */ true);
scroll(x: number, y: number, shouldHidePopups = true) {
if (shouldHidePopups) {
this.hideChaff(/* opt_onlyClosePopups= */ true);
}

// Keep scrolling within the bounds of the content.
const metrics = this.getMetrics();
Expand Down Expand Up @@ -2770,7 +2773,7 @@ export class WorkspaceSvg

deltaX *= scale;
deltaY *= scale;
this.scroll(this.scrollX + deltaX, this.scrollY + deltaY);
this.scroll(this.scrollX + deltaX, this.scrollY + deltaY, false);
}

/** See IFocusableNode.getFocusableElement. */
Expand Down
Loading