Skip to content

Commit c88ebf1

Browse files
authored
fix: Don't add padding around zero-width fields. (#8738)
1 parent c68d645 commit c88ebf1

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

core/field.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ export abstract class Field<T = any>
8383
*/
8484
DEFAULT_VALUE: T | null = null;
8585

86-
/** Non-breaking space. */
87-
static readonly NBSP = '\u00A0';
88-
8986
/**
9087
* A value used to signal when a field's constructor should *not* set the
9188
* field's value or run configure_, and should allow a subclass to do that
@@ -905,17 +902,6 @@ export abstract class Field<T = any>
905902
if (this.isDirty_) {
906903
this.render_();
907904
this.isDirty_ = false;
908-
} else if (this.visible_ && this.size_.width === 0) {
909-
// If the field is not visible the width will be 0 as well, one of the
910-
// problems with the old system.
911-
this.render_();
912-
// Don't issue a warning if the field is actually zero width.
913-
if (this.size_.width !== 0) {
914-
console.warn(
915-
'Deprecated use of setting size_.width to 0 to rerender a' +
916-
' field. Set field.isDirty_ to true instead.',
917-
);
918-
}
919905
}
920906
return this.size_;
921907
}
@@ -979,16 +965,10 @@ export abstract class Field<T = any>
979965
*/
980966
protected getDisplayText_(): string {
981967
let text = this.getText();
982-
if (!text) {
983-
// Prevent the field from disappearing if empty.
984-
return Field.NBSP;
985-
}
986968
if (text.length > this.maxDisplayLength) {
987969
// Truncate displayed string and add an ellipsis ('...').
988970
text = text.substring(0, this.maxDisplayLength - 2) + '…';
989971
}
990-
// Replace whitespace with non-breaking spaces so the text doesn't collapse.
991-
text = text.replace(/\s/g, Field.NBSP);
992972
if (this.sourceBlock_ && this.sourceBlock_.RTL) {
993973
// The SVG is LTR, force text to be RTL by adding an RLM.
994974
text += '\u200F';

core/renderers/common/info.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ export class RenderInfo {
457457
}
458458
}
459459

460+
// Don't add padding after zero-width fields.
461+
if (prev && Types.isField(prev) && prev.width === 0) {
462+
return this.constants_.NO_PADDING;
463+
}
464+
460465
return this.constants_.MEDIUM_PADDING;
461466
}
462467

core/renderers/geras/info.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ export class RenderInfo extends BaseRenderInfo {
164164
if (!Types.isInput(prev) && (!next || Types.isStatementInput(next))) {
165165
// Between an editable field and the end of the row.
166166
if (Types.isField(prev) && prev.isEditable) {
167+
if (prev.width === 0) {
168+
return this.constants_.NO_PADDING;
169+
}
167170
return this.constants_.MEDIUM_PADDING;
168171
}
169172
// Padding at the end of an icon-only row to make the block shape clearer.
@@ -276,6 +279,9 @@ export class RenderInfo extends BaseRenderInfo {
276279
Types.isField(next) &&
277280
prev.isEditable === next.isEditable
278281
) {
282+
if (prev.width === 0) {
283+
return this.constants_.NO_PADDING;
284+
}
279285
return this.constants_.LARGE_PADDING;
280286
}
281287

core/renderers/thrasos/info.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export class RenderInfo extends BaseRenderInfo {
109109
if (!Types.isInput(prev) && !next) {
110110
// Between an editable field and the end of the row.
111111
if (Types.isField(prev) && prev.isEditable) {
112+
if (prev.width === 0) {
113+
return this.constants_.NO_PADDING;
114+
}
112115
return this.constants_.MEDIUM_PADDING;
113116
}
114117
// Padding at the end of an icon-only row to make the block shape clearer.
@@ -204,6 +207,9 @@ export class RenderInfo extends BaseRenderInfo {
204207
Types.isField(next) &&
205208
prev.isEditable === next.isEditable
206209
) {
210+
if (prev.width === 0) {
211+
return this.constants_.NO_PADDING;
212+
}
207213
return this.constants_.LARGE_PADDING;
208214
}
209215

core/renderers/zelos/info.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ export class RenderInfo extends BaseRenderInfo {
186186
if (prev && Types.isLeftSquareCorner(prev) && next && Types.isHat(next)) {
187187
return this.constants_.NO_PADDING;
188188
}
189+
190+
// No space after zero-width fields.
191+
if (prev && Types.isField(prev) && prev.width === 0) {
192+
return this.constants_.NO_PADDING;
193+
}
194+
189195
return this.constants_.MEDIUM_PADDING;
190196
}
191197

0 commit comments

Comments
 (0)