fix(tui): keep truncateMiddle within maxLength when maxLength is 1 or 2#37460
Open
VINODvoid wants to merge 1 commit into
Open
fix(tui): keep truncateMiddle within maxLength when maxLength is 1 or 2#37460VINODvoid wants to merge 1 commit into
VINODvoid wants to merge 1 commit into
Conversation
keepEnd is 0 when maxLength <= 2, and str.slice(-0) returns the whole string rather than an empty tail, so truncateMiddle returned its input with an ellipsis attached instead of truncating. Use a positive index so the empty tail is actually empty. Behavior is unchanged for maxLength >= 3. Reachable from dialog-select.tsx:701, where Math.max(1, ...) clamps to exactly the broken value on terminals narrower than ~15 columns.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
This previous PR seems to have tackled the same bug. You should verify whether PR #34482 was already merged or closed, and if it was merged, PR #37460 may be redundant. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #37458
Type of change
What does this PR do?
truncateMiddlehands back a string longer thanmaxLengthwhenmaxLengthis 1 or 2:The last line is
str.slice(0, keepStart) + ellipsis + str.slice(-keepEnd).keepEndcomes out as 0 for those two cases, andslice(-0)is justslice(0)in JS, so you get the whole string back where an empty tail was meant to go.Swapped it for
str.slice(str.length - keepEnd), which isslice(str.length)->""whenkeepEndis 0. For anything >= 1 the two are the same expression, somaxLength >= 3doesn't move.I ran into this from
dialog-select.tsx:701:The
Math.max(1, ...)is there to keep the width sane on small terminals, except 1 is the value that breaks. So under ~15 columns the detail line printed in full and ran past the dialog.splash.ts:203does the sameMath.max(1, ...)thing.#37369 fixes the identical
-0slip intruncateLeft. This is the sibling it doesn't touch.How did you verify your code works?
Added
packages/tui/test/util/locale.test.ts. Put the old line back and 2 of the 4 fail:With the fix, 4 pass.
Diffed old vs new across
maxLength1..12 on a 10-char string. Only 1 and 2 move:Also ran the
dialog-select.tsx:701expression itself at widths 10-20. Widths 13 and 14 gave back 40 and 41 chars before, correct output after.packages/tui: 195 pass, 0 fail. Pre-push typecheck: 30/30 packages.Screenshots / recordings
Nothing to show really — text that should have been truncated now is.
Checklist