mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
fix: widget positioning (#7507)
* chore: delete dead code * chore: moves location updating into the block * chore: change dragging to use update component locations * fix: field widgets not being moved when blocks are editted * chore: remove unnecessary resizeEditor_ calls * chore: format * chore: fix build * fix: tests * chore: PR comments * chore: format
This commit is contained in:
@@ -33,7 +33,6 @@ import {Coordinate} from './utils/coordinate.js';
|
||||
import * as userAgent from './utils/useragent.js';
|
||||
import * as WidgetDiv from './widgetdiv.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
import * as renderManagement from './render_management.js';
|
||||
import {Size} from './utils/size.js';
|
||||
|
||||
/**
|
||||
@@ -251,6 +250,14 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
return super.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the field that it has changed locations. Moves the widget div to
|
||||
* be in the correct place if it is open.
|
||||
*/
|
||||
onLocationChange(): void {
|
||||
if (this.isBeingEdited_) this.resizeEditor_();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the colour of the htmlInput given the current validity of the
|
||||
* field's value.
|
||||
@@ -263,7 +270,6 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
// This logic is done in render_ rather than doValueInvalid_ or
|
||||
// doValueUpdate_ so that the code is more centralized.
|
||||
if (this.isBeingEdited_) {
|
||||
this.resizeEditor_();
|
||||
const htmlInput = this.htmlInput_ as HTMLElement;
|
||||
if (!this.isTextValid_) {
|
||||
dom.addClass(htmlInput, 'blocklyInvalidInput');
|
||||
@@ -576,11 +582,6 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Resize the widget div after the block has finished rendering.
|
||||
renderManagement.finishQueuedRenders().then(() => {
|
||||
this.resizeEditor_();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -631,7 +632,7 @@ 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 field if necessary.
|
||||
* position of the text input if necessary.
|
||||
*
|
||||
* @returns True for rendered workspaces, as we never want to hide the widget
|
||||
* div.
|
||||
@@ -642,13 +643,13 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
// rendered blocks.
|
||||
if (!(block instanceof BlockSvg)) return false;
|
||||
|
||||
bumpObjects.bumpIntoBounds(
|
||||
const bumped = bumpObjects.bumpIntoBounds(
|
||||
this.workspace_!,
|
||||
this.workspace_!.getMetricsManager().getViewMetrics(true),
|
||||
block,
|
||||
);
|
||||
|
||||
this.resizeEditor_();
|
||||
if (!bumped) this.resizeEditor_();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user