Skip to content

Fix SortPrompt display-width clipping - #3050

Open
Tomeshwari-02 wants to merge 1 commit into
Karanjot786:mainfrom
Tomeshwari-02:issue/3040-sortprompt-display-width
Open

Fix SortPrompt display-width clipping#3050
Tomeshwari-02 wants to merge 1 commit into
Karanjot786:mainfrom
Tomeshwari-02:issue/3040-sortprompt-display-width

Conversation

@Tomeshwari-02

@Tomeshwari-02 Tomeshwari-02 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • clip SortPrompt rows by terminal display width instead of string length
  • add a regression test for wide-character item labels

Validation

  • bun vitest run packages/ui/src/SortPrompt.test.ts --config vitest.config.ts

Fixes #3040

Summary by CodeRabbit

  • Bug Fixes
    • Improved sorting prompt rendering for wide and Unicode characters.
    • Ensured list entries remain within the available display width without visual overflow.

@github-actions github-actions Bot added area:ui @termuijs/ui type:testing +10 pts. Tests. labels Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SortPrompt row rendering now uses display-width-aware truncation, and a test verifies wide Unicode content remains within the configured prompt width.

Changes

SortPrompt width handling

Layer / File(s) Summary
Display-width row rendering
packages/ui/src/SortPrompt.ts, packages/ui/src/SortPrompt.test.ts
SortPrompt replaces code-unit slicing with truncate(line, width, ''); a regression test checks that wide-character output fits the prompt width.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Karanjot786/TermUI#3041 — Addresses the same display-width-aware truncation pattern for another prompt component.

Possibly related PRs

Suggested labels: type:bug, quality:clean, level:beginner

Suggested reviewers: karanjot786

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is too sparse for the template; it lacks the package, type-of-change, checklist, and reviewer notes sections. Fill out the full template, especially Which package(s), Type of Change, Checklist, and any relevant notes/screenshots.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly describes the main change to SortPrompt clipping behavior.
Linked Issues check ✅ Passed The code and regression test address the SortPrompt width-clipping bug and validate wide-character rendering within bounds.
Out of Scope Changes check ✅ Passed Only the SortPrompt clipping logic and a focused test were changed, which stays within the issue scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ui/src/SortPrompt.test.ts`:
- Around line 158-170: Strengthen the SortPrompt rendering tests around
prompt.updateRect and prompt.render by adding mixed-width and combining-grapheme
boundary cases, not just repeated CJK characters. Assert each rendered row both
fits the configured width and preserves the expected complete grapheme/content,
preventing empty or over-truncated output from passing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b3a28f5c-7d55-4d60-a8f1-a04d7ce3be5a

📥 Commits

Reviewing files that changed from the base of the PR and between 46503a5 and 8f41f03.

📒 Files selected for processing (2)
  • packages/ui/src/SortPrompt.test.ts
  • packages/ui/src/SortPrompt.ts

Comment on lines +158 to +170

it('renders wide-character rows within the prompt width', () => {
const prompt = new SortPrompt(['\u8868\u8868\u8868\u8868']);
const screen = new Screen(6, 2);
const writeSpy = vi.spyOn(screen, 'writeString');

prompt.updateRect({ x: 0, y: 0, width: 5, height: 2 });
prompt.render(screen);

const rendered = String(writeSpy.mock.calls[0][2]);
expect(stringWidth(rendered)).toBeLessThanOrEqual(5);
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert content and grapheme preservation, not only width.

This test covers only repeated CJK characters and would pass for an empty or over-truncated row. Add mixed-width and combining-grapheme boundary cases, asserting the complete grapheme is present as well as fitting within the width.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/SortPrompt.test.ts` around lines 158 - 170, Strengthen the
SortPrompt rendering tests around prompt.updateRect and prompt.render by adding
mixed-width and combining-grapheme boundary cases, not just repeated CJK
characters. Assert each rendered row both fits the configured width and
preserves the expected complete grapheme/content, preventing empty or
over-truncated output from passing.

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

Labels

area:ui @termuijs/ui type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] SortPrompt row rendering slices by code units instead of display width

1 participant