Skip to content

fix(terminal): clamp DCH count to cells remaining from cursor#13265

Open
Jason-Shen2 wants to merge 1 commit into
warpdotdev:masterfrom
Jason-Shen2:fix/terminal-dch-count-clamp
Open

fix(terminal): clamp DCH count to cells remaining from cursor#13265
Jason-Shen2 wants to merge 1 commit into
warpdotdev:masterfrom
Jason-Shen2:fix/terminal-dch-count-clamp

Conversation

@Jason-Shen2

Copy link
Copy Markdown

Fixes #12820.

Problem

When DCH (CSI Pn P - Delete Character) receives a count greater than the number of cells remaining from the cursor to end-of-line, the count was clamped to the full row width (cols). This caused the trailing blank-fill loop (at cols - count) to start at an index before the cursor column, erroneously erasing characters before the cursor.

Root Cause

In ansi_handler.rs delete_chars(), count was clamped to min(count, cols) (full row width), then the blank-fill started at cols - count. When count > cols - cursor_col, the blank-fill start falls before the cursor, wiping cells that should be preserved.

Fix

Clamp count to cells remaining from cursor (matching the existing pattern in insert_blank): min(count, cols - cursor.point.col).

Verification

Added regression test test_delete_chars_count_exceeding_eol_does_not_erase_before_cursor.

Fixes warpdotdev#12820. When CSI Pn P (DCH - Delete Character) received a count
greater than the number of cells remaining from cursor to end-of-line,
the count was clamped to the full row width (cols). This caused the
trailing blank-fill loop to start at cols - count, which could land
before the cursor column, erroneously erasing characters before the
cursor.

The fix mirrors the existing pattern in insert_blank: clamp count to
cols - cursor.point.col so DCH never reaches cells before the cursor.
Added a regression test to verify characters before the cursor are
preserved when count exceeds cells to EOL.
@cla-bot cla-bot Bot added the cla-signed label Jun 30, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jun 30, 2026
@oz-for-oss

oz-for-oss Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@Jason-Shen2

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot 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.

Overview

This PR updates terminal DCH handling to clamp the delete count to the cells remaining from the cursor to the end of the row, and adds a regression test for an over-large delete count preserving cells before the cursor.

Concerns

  • This is a user-facing terminal behavior change, but the PR does not include screenshots or a screen recording demonstrating the fix end to end. For this user-facing change, please include a screenshot or short recording showing an oversized DCH count preserving characters before the cursor while blanking cells at/after the cursor.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

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

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DCH (CSI Pn P) erases characters before the cursor when count exceeds cells to end-of-line

1 participant