You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
truncateMiddle overflows when the width is 1 or 2 #59912
For width 4 and above the result fits ("ab…j", "abcd…ghij").
Cause
keepEnd = Math.floor((maxLength - 1) / 2) is 0 for widths 1 and 2, and str.slice(-0) is str.slice(0), i.e. the whole string.
Real call site
packages/tui/src/ui/dialog-select.tsx:987 passes Math.max(1, props.width) to Locale.truncateMiddle, so a narrow dialog renders a line wider than the pane.
Expected
The result should never be wider than maxLength: width 1 should give "…", width 2 "a…".
Thanks for the clear report. I reproduced this on the latest dev (3d7eceb): with "abcdefghij", both truncateMiddle in packages/util/src/path.ts and Locale.truncateMiddle in packages/tui/src/util/locale.ts return "…abcdefghij" for width 1 and "a…abcdefghij" for width 2. Widths 3 and up fit. In v2.2.0 both functions have the same code. The script below calls both copies and exits with status 1 when a result is longer than the requested width.
Related: earlier reports of the same slice(-0) problem (#37458, #34395, #20880, #41054) were closed without a fix. Open PR #55953 fixes the packages/util copy but not the TUI one.
Activity
opencodejr commentedon Oct 28, 2026
Thanks for the clear report. I reproduced this on the latest
dev(3d7eceb): with"abcdefghij", bothtruncateMiddleinpackages/util/src/path.tsandLocale.truncateMiddleinpackages/tui/src/util/locale.tsreturn"…abcdefghij"for width 1 and"a…abcdefghij"for width 2. Widths 3 and up fit. In v2.2.0 both functions have the same code. The script below calls both copies and exits with status 1 when a result is longer than the requested width.Related: earlier reports of the same
slice(-0)problem (#37458, #34395, #20880, #41054) were closed without a fix. Open PR #55953 fixes thepackages/utilcopy but not the TUI one.Reproduction script (repro.ts)
Run it:
bun repro.ts