Skip to content

Commit 9a7de53

Browse files
authored
fix: Fix crash when resizing page while editing a field. (#8646)
* fix: Fix crash when resizing page while editing a field. * refactor: Clean up positioning and exceptions.
1 parent 378d5a9 commit 9a7de53

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

core/field_input.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import {
2828
UnattachedFieldError,
2929
} from './field.js';
3030
import {Msg} from './msg.js';
31+
import * as renderManagement from './render_management.js';
3132
import * as aria from './utils/aria.js';
32-
import {Coordinate} from './utils/coordinate.js';
3333
import * as dom from './utils/dom.js';
3434
import {Size} from './utils/size.js';
3535
import * as userAgent from './utils/useragent.js';
@@ -630,22 +630,22 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
630630

631631
/** Resize the editor to fit the text. */
632632
protected resizeEditor_() {
633-
const block = this.getSourceBlock();
634-
if (!block) {
635-
throw new UnattachedFieldError();
636-
}
637-
const div = WidgetDiv.getDiv();
638-
const bBox = this.getScaledBBox();
639-
div!.style.width = bBox.right - bBox.left + 'px';
640-
div!.style.height = bBox.bottom - bBox.top + 'px';
633+
renderManagement.finishQueuedRenders().then(() => {
634+
const block = this.getSourceBlock();
635+
if (!block) throw new UnattachedFieldError();
636+
const div = WidgetDiv.getDiv();
637+
const bBox = this.getScaledBBox();
638+
div!.style.width = bBox.right - bBox.left + 'px';
639+
div!.style.height = bBox.bottom - bBox.top + 'px';
641640

642-
// In RTL mode block fields and LTR input fields the left edge moves,
643-
// whereas the right edge is fixed. Reposition the editor.
644-
const x = block.RTL ? bBox.right - div!.offsetWidth : bBox.left;
645-
const xy = new Coordinate(x, bBox.top);
641+
// In RTL mode block fields and LTR input fields the left edge moves,
642+
// whereas the right edge is fixed. Reposition the editor.
643+
const x = block.RTL ? bBox.right - div!.offsetWidth : bBox.left;
644+
const y = bBox.top;
646645

647-
div!.style.left = xy.x + 'px';
648-
div!.style.top = xy.y + 'px';
646+
div!.style.left = `${x}px`;
647+
div!.style.top = `${y}px`;
648+
});
649649
}
650650

651651
/**
@@ -657,7 +657,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
657657
* div.
658658
*/
659659
override repositionForWindowResize(): boolean {
660-
const block = this.getSourceBlock();
660+
const block = this.getSourceBlock()?.getRootBlock();
661661
// This shouldn't be possible. We should never have a WidgetDiv if not using
662662
// rendered blocks.
663663
if (!(block instanceof BlockSvg)) return false;

0 commit comments

Comments
 (0)