Skip to content

fix(tui): truncateMiddle returns the whole string when maxLength is 1 or 2 - #34482

Closed
Osamaali313 wants to merge 1 commit into
anomalyco:devfrom
Osamaali313:fix/truncate-middle-small-widths
Closed

Osamaali313 wants to merge 1 commit into
anomalyco:devfrom
Osamaali313:fix/truncate-middle-small-widths

Conversation

@Osamaali313

@Osamaali313 Osamaali313 commented Jun 29, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #20880

Type of change

  • Bug fix

What does this PR do?

truncateMiddle (packages/tui/src/util/locale.ts) returns the whole string when maxLength is 1 or 2. At those widths keepEnd is 0, and str.slice(-0) slices from index 0 (returns everything) instead of nothing — so the result is longer than the input, and the run splash detail line overflows on very narrow terminals. The fix skips the end slice when keepEnd is 0.

How did you verify your code works?

Added packages/tui/test/util/locale.test.ts: truncateMiddle("hello-world", 1) now returns "…" and (..., 2) returns "h…"; widths >= 3 are unchanged.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

keepEnd is 0 at those widths, and str.slice(-0) returns the entire string, so truncateMiddle produced output longer than the input (e.g. the run splash detail line overflows on narrow terminals). Skip the end slice when keepEnd is 0.
Copilot AI review requested due to automatic review settings June 29, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 29, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(util): truncateMiddle returns full string when maxLength <= 2 due to slice(-0)

2 participants