Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,7 @@ export abstract class Field<T = any>
totalHeight = Math.max(totalHeight, constants!.FIELD_BORDER_RECT_HEIGHT);
}

this.size_.height = totalHeight;
this.size_.width = totalWidth;
this.size_ = new Size(totalWidth, totalHeight);

this.positionTextElement_(xOffset, contentWidth);
this.positionBorderRect_();
Expand Down
7 changes: 3 additions & 4 deletions core/field_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as aria from './utils/aria.js';
import {Coordinate} from './utils/coordinate.js';
import * as dom from './utils/dom.js';
import * as parsing from './utils/parsing.js';
import {Size} from './utils/size.js';
import * as utilsString from './utils/string.js';
import {Svg} from './utils/svg.js';

Expand Down Expand Up @@ -553,8 +554,7 @@ export class FieldDropdown extends Field<string> {
} else {
arrowWidth = dom.getTextWidth(this.arrow as SVGTSpanElement);
}
this.size_.width = imageWidth + arrowWidth + xPadding * 2;
this.size_.height = height;
this.size_ = new Size(imageWidth + arrowWidth + xPadding * 2, height);

let arrowX = 0;
if (block.RTL) {
Expand Down Expand Up @@ -595,8 +595,7 @@ export class FieldDropdown extends Field<string> {
height / 2 - this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_SIZE / 2,
);
}
this.size_.width = textWidth + arrowWidth + xPadding * 2;
this.size_.height = height;
this.size_ = new Size(textWidth + arrowWidth + xPadding * 2, height);

this.positionTextElement_(xPadding, textWidth);
}
Expand Down
26 changes: 24 additions & 2 deletions core/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ import type {WorkspaceSvg} from './workspace_svg.js';
*/
type InputTypes = string | number;

/**
* The minimum width of an input field.
*/
const MINIMUM_WIDTH = 14;

/**
* Abstract class for an editable input field.
*
Expand Down Expand Up @@ -115,8 +120,8 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
*/
protected override get size_() {
const s = super.size_;
if (s.width < 14) {
s.width = 14;
if (s.width < MINIMUM_WIDTH) {
s.width = MINIMUM_WIDTH;
}

return s;
Expand Down Expand Up @@ -732,6 +737,23 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
return true;
}

/**
* Position a field's text element after a size change. This handles both LTR
* and RTL positioning.
*
* @param xMargin x offset to use when positioning the text element.
* @param contentWidth The content width.
*/
protected override positionTextElement_(
xMargin: number,
contentWidth: number,
) {
const effectiveWidth = xMargin * 2 + contentWidth;
const delta =
effectiveWidth < MINIMUM_WIDTH ? (MINIMUM_WIDTH - effectiveWidth) / 2 : 0;
super.positionTextElement_(xMargin + delta, contentWidth);
}

/**
* Use the `getText_` developer hook to override the field's text
* representation. When we're currently editing, return the current HTML value
Expand Down
Loading