File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -849,8 +849,7 @@ export abstract class Field<T = any>
849849 totalHeight = Math . max ( totalHeight , constants ! . FIELD_BORDER_RECT_HEIGHT ) ;
850850 }
851851
852- this . size_ . height = totalHeight ;
853- this . size_ . width = totalWidth ;
852+ this . size_ = new Size ( totalWidth , totalHeight ) ;
854853
855854 this . positionTextElement_ ( xOffset , contentWidth ) ;
856855 this . positionBorderRect_ ( ) ;
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import * as aria from './utils/aria.js';
2929import { Coordinate } from './utils/coordinate.js' ;
3030import * as dom from './utils/dom.js' ;
3131import * as parsing from './utils/parsing.js' ;
32+ import { Size } from './utils/size.js' ;
3233import * as utilsString from './utils/string.js' ;
3334import { Svg } from './utils/svg.js' ;
3435
@@ -553,8 +554,7 @@ export class FieldDropdown extends Field<string> {
553554 } else {
554555 arrowWidth = dom . getTextWidth ( this . arrow as SVGTSpanElement ) ;
555556 }
556- this . size_ . width = imageWidth + arrowWidth + xPadding * 2 ;
557- this . size_ . height = height ;
557+ this . size_ = new Size ( imageWidth + arrowWidth + xPadding * 2 , height ) ;
558558
559559 let arrowX = 0 ;
560560 if ( block . RTL ) {
@@ -595,8 +595,7 @@ export class FieldDropdown extends Field<string> {
595595 height / 2 - this . getConstants ( ) ! . FIELD_DROPDOWN_SVG_ARROW_SIZE / 2 ,
596596 ) ;
597597 }
598- this . size_ . width = textWidth + arrowWidth + xPadding * 2 ;
599- this . size_ . height = height ;
598+ this . size_ = new Size ( textWidth + arrowWidth + xPadding * 2 , height ) ;
600599
601600 this . positionTextElement_ ( xPadding , textWidth ) ;
602601 }
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ import type {WorkspaceSvg} from './workspace_svg.js';
4545 */
4646type InputTypes = string | number ;
4747
48+ /**
49+ * The minimum width of an input field.
50+ */
51+ const MINIMUM_WIDTH = 14 ;
52+
4853/**
4954 * Abstract class for an editable input field.
5055 *
@@ -113,8 +118,8 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
113118 */
114119 protected override get size_ ( ) {
115120 const s = super . size_ ;
116- if ( s . width < 14 ) {
117- s . width = 14 ;
121+ if ( s . width < MINIMUM_WIDTH ) {
122+ s . width = MINIMUM_WIDTH ;
118123 }
119124
120125 return s ;
@@ -730,6 +735,23 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
730735 return true ;
731736 }
732737
738+ /**
739+ * Position a field's text element after a size change. This handles both LTR
740+ * and RTL positioning.
741+ *
742+ * @param xMargin x offset to use when positioning the text element.
743+ * @param contentWidth The content width.
744+ */
745+ protected override positionTextElement_ (
746+ xMargin : number ,
747+ contentWidth : number ,
748+ ) {
749+ const effectiveWidth = xMargin * 2 + contentWidth ;
750+ const delta =
751+ effectiveWidth < MINIMUM_WIDTH ? ( MINIMUM_WIDTH - effectiveWidth ) / 2 : 0 ;
752+ super . positionTextElement_ ( xMargin + delta , contentWidth ) ;
753+ }
754+
733755 /**
734756 * Use the `getText_` developer hook to override the field's text
735757 * representation. When we're currently editing, return the current HTML value
You can’t perform that action at this time.
0 commit comments