-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: Fix regressions in Field
.
#9011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,9 @@ export abstract class Field<T = any> | |
*/ | ||
DEFAULT_VALUE: T | null = null; | ||
|
||
/** Non-breaking space. */ | ||
static readonly NBSP = '\u00A0'; | ||
|
||
/** | ||
* A value used to signal when a field's constructor should *not* set the | ||
* field's value or run configure_, and should allow a subclass to do that | ||
|
@@ -110,7 +113,28 @@ export abstract class Field<T = any> | |
* field is not yet initialized. Is *not* guaranteed to be accurate. | ||
*/ | ||
private tooltip: Tooltip.TipInfo | null = null; | ||
protected size_: Size; | ||
|
||
/** This field's dimensions. */ | ||
private size: Size = new Size(0, 0); | ||
|
||
/** | ||
* Gets the size of this field. Because getSize() and updateSize() have side | ||
* effects, this acts as a shim for subclasses which wish to adjust field | ||
* bounds when setting/getting the size without triggering unwanted rendering | ||
* or other side effects. Note that subclasses must override *both* get and | ||
* set if either is overridden; the implementation may just call directly | ||
* through to super, but it must exist per the JS spec. | ||
*/ | ||
protected get size_(): Size { | ||
return this.size; | ||
} | ||
|
||
/** | ||
* Sets the size of this field. | ||
*/ | ||
protected set size_(newValue: Size) { | ||
this.size = newValue; | ||
} | ||
Comment on lines
+117
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Styleguide says "At least one accessor for a property must be non-trivial: do not define "pass-through" accessors only for the purpose of hiding a property." I gather you are doing this in order to be able to write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you noted, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to think about this for a bit, but I think I see a way to do this without needing to have accessors on The obvious approach is to have the But if the class FieldInput {
constructor() {
this.size_ ??= new Size(0, 0);
}
} or if the class FieldInput {
constructor() {
super();
delete this.size_;
}
} then I think it's possible to have the behaviour you have here without the mostly-useless accessors on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, I think that even if you keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the mostly-useless accessors (which most fields can just ignore) over the kludgy approaches mentioned above. |
||
|
||
/** The rendered field's SVG group element. */ | ||
protected fieldGroup_: SVGGElement | null = null; | ||
|
@@ -973,6 +997,8 @@ export abstract class Field<T = any> | |
// Truncate displayed string and add an ellipsis ('...'). | ||
text = text.substring(0, this.maxDisplayLength - 2) + '…'; | ||
} | ||
// Replace whitespace with non-breaking spaces so the text doesn't collapse. | ||
text = text.replace(/\s/g, Field.NBSP); | ||
if (this.sourceBlock_ && this.sourceBlock_.RTL) { | ||
// The SVG is LTR, force text to be RTL by adding an RLM. | ||
text += '\u200F'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style guide suggests something like
sizeInternal
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused about this, why? it's already
private
, why would we also add the wordinternal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoting the Styleguide section on get and set accesors says:
They do not provide a rational, but I suspect the reason is to avoid clashing with the name of the accessors. In this case the accessors are named
size_
(which, with the trailing underscore, is contrary to current naming policy) but if it weresize
then the internal property would need to be named something else.