Skip to content

fix(tui): correct truncateLeft output when len is 1 - #37369

Closed
chinesepowered wants to merge 1 commit into
anomalyco:devfrom
chinesepowered:fix/truncateleft-len-1
Closed

chinesepowered wants to merge 1 commit into
anomalyco:devfrom
chinesepowered:fix/truncateleft-len-1

Conversation

@chinesepowered

Copy link
Copy Markdown

Issue for this PR

Closes #37368

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

truncateLeft(str, len) ended with "…" + str.slice(-(len - 1)). When len === 1 that is str.slice(-0), and slice(-0) equals slice(0) — the whole string — so the function returned something longer than the input (truncateLeft("abcdef", 1) → "…abcdef").

This replaces the negative index with an equivalent positive one: str.slice(str.length - (len - 1)). At len === 1 that becomes str.slice(str.length) → "", giving "…". For every len >= 2 the two expressions are identical, so existing behavior is unchanged. This also brings it in line with the sibling truncate(), which already handles len === 1 correctly.

How did you verify your code works?

Ran the old and new implementations side by side over a range of lengths:

  • len === 1: old "…abcdef" (7 chars) → new "…" (1 char) ✅
  • len === 2, 3, 5: identical output to before ("…f", "…ef", "…cdef") ✅
  • len >= str.length: returns the string unchanged ✅

One-character diff, no caller changes needed.

Screenshots / recordings

N/A — not a UI change.

Checklist

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

@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.

truncateLeft returns a longer string than the input when len is 1

1 participant