Skip to content

Commit 14e1ef6

Browse files
authored
fix: Fix regressions in Field. (#9011)
1 parent 6bee1ca commit 14e1ef6

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

core/field.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export abstract class Field<T = any>
8484
*/
8585
DEFAULT_VALUE: T | null = null;
8686

87+
/** Non-breaking space. */
88+
static readonly NBSP = '\u00A0';
89+
8790
/**
8891
* A value used to signal when a field's constructor should *not* set the
8992
* field's value or run configure_, and should allow a subclass to do that
@@ -106,7 +109,28 @@ export abstract class Field<T = any>
106109
* field is not yet initialized. Is *not* guaranteed to be accurate.
107110
*/
108111
private tooltip: Tooltip.TipInfo | null = null;
109-
protected size_: Size;
112+
113+
/** This field's dimensions. */
114+
private size: Size = new Size(0, 0);
115+
116+
/**
117+
* Gets the size of this field. Because getSize() and updateSize() have side
118+
* effects, this acts as a shim for subclasses which wish to adjust field
119+
* bounds when setting/getting the size without triggering unwanted rendering
120+
* or other side effects. Note that subclasses must override *both* get and
121+
* set if either is overridden; the implementation may just call directly
122+
* through to super, but it must exist per the JS spec.
123+
*/
124+
protected get size_(): Size {
125+
return this.size;
126+
}
127+
128+
/**
129+
* Sets the size of this field.
130+
*/
131+
protected set size_(newValue: Size) {
132+
this.size = newValue;
133+
}
110134

111135
/** The rendered field's SVG group element. */
112136
protected fieldGroup_: SVGGElement | null = null;
@@ -969,6 +993,8 @@ export abstract class Field<T = any>
969993
// Truncate displayed string and add an ellipsis ('...').
970994
text = text.substring(0, this.maxDisplayLength - 2) + '…';
971995
}
996+
// Replace whitespace with non-breaking spaces so the text doesn't collapse.
997+
text = text.replace(/\s/g, Field.NBSP);
972998
if (this.sourceBlock_ && this.sourceBlock_.RTL) {
973999
// The SVG is LTR, force text to be RTL by adding an RLM.
9741000
text += '\u200F';

core/field_image.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class FieldImage extends Field<string> {
2727
* of the field.
2828
*/
2929
private static readonly Y_PADDING = 1;
30-
protected override size_: Size;
3130
protected readonly imageHeight: number;
3231

3332
/** The function to be called when this field is clicked. */

core/field_input.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
100100
*/
101101
override SERIALIZABLE = true;
102102

103+
/**
104+
* Sets the size of this field. Although this appears to be a no-op, it must
105+
* exist since the getter is overridden below.
106+
*/
107+
protected override set size_(newValue: Size) {
108+
super.size_ = newValue;
109+
}
110+
111+
/**
112+
* Returns the size of this field, with a minimum width of 14.
113+
*/
114+
protected override get size_() {
115+
const s = super.size_;
116+
if (s.width < 14) {
117+
s.width = 14;
118+
}
119+
120+
return s;
121+
}
122+
103123
/**
104124
* @param value The initial value of the field. Should cast to a string.
105125
* Defaults to an empty string if null or undefined. Also accepts

core/field_variable.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class FieldVariable extends FieldDropdown {
4949
* dropdown.
5050
*/
5151
variableTypes: string[] | null = [];
52-
protected override size_: Size;
5352

5453
/** The variable model associated with this field. */
5554
private variable: IVariableModel<IVariableState> | null = null;

0 commit comments

Comments
 (0)