Skip to content

fix(terminal): keep cursor on its logical line during width reflow - #1100

Open
not-exist wants to merge 1 commit into
Kuddev:mainfrom
not-exist:fix/issue-1091-resize-scroll
Open

not-exist wants to merge 1 commit into
Kuddev:mainfrom
not-exist:fix/issue-1091-resize-scroll

Conversation

@not-exist

Copy link
Copy Markdown
Contributor

Result / 用户结果

When a terminal pane has a long scrollback and the user has scrolled away from the bottom, dragging the pane or window width through a soft-wrap boundary could leave the terminal cursor one logical line below the prompt. A TUI that repaints relative to the cursor (for example Claude Code) then drew its input box off the intended row and left stale rows below it.

This change keeps the cursor on the same logical line and column across every intermediate width of a drag, in both directions.

Part of #1091. The report also mentions scrollbar movement and occasional wheel-scroll glitches; those are not claimed as fixed here and still need native Windows/ConPTY verification.

Design / 设计边界

  • Responsibility and affected modules: pebrel_terminal/src/grid/resize.rs. Grid reflow owns cursor placement; the app continues to only forward viewport geometry. No UI, settings, or persistence code changes.
  • Why this belongs here; interfaces that remain unchanged: cursor anchoring is terminal state and must be decided together with the row reflow. Public Grid/Term APIs are unchanged.
  • Dependency, data-format, threading, or lifetime changes: none.
  • Compatibility and migration/fallback behavior: no persisted format changes. A cursor on a blank logical line keeps the previous reflow bookkeeping, so the change never invents a content position.

The previous anchor counted blank logical lines, whose number reflow does not preserve, and then treated the start row of a wrapped line below the cursor as the anchor itself. The new anchor counts only non-empty logical lines and locates the cursor's own line before restoring its column offset.

Evidence / 验证依据

  • Commands and actual results:
    • cargo test -p pebrel_terminal — pass (408 library tests plus all integration targets).
    • cargo test -p pebrel --bin pebrel --features gpui-shell -- resize — 9 passed.
    • cargo test -p pebrel --bin pebrel --features gpui-shell -- reflow — 2 passed.
    • cargo check -p pebrel --bin pebrel --features gpui-shell --tests --locked — pass.
    • python3 scripts/check_architecture.py --base 76f74be1 — pass; only existing tighten notices.
    • cargo fmt --all -- --check — pass.
    • cargo test -p pebrel --test file_line_budget — 2 passed.
  • Regression tests: grid::tests::reflow_keeps_cursor_on_its_logical_line_while_scrolled_back builds 120 lines of output, scrolls back 30 rows, then resizes 80→40→80 one column at a time and asserts the cursor stays on L0118 at column 10. It fails before the change at 69 columns (L0119) and passes after.
  • UI changes: no new UI strings or layout. No screenshots: validation was on Linux/headless; Windows ConPTY and a real Claude Code session were not run locally. Native Windows tests and visual acceptance remain for maintainers/CI.
  • Hot-path changes: reflow already walks the visible rows; the anchor scan is bounded to the visible region and adds no allocation. No broader performance claim is made.

Required Review / 必须确认

  • I followed CONTRIBUTING.md, docs/architecture.md, and docs/project-constraints.md.
  • I split responsibilities, not arbitrary line ranges; no duplicate behavior authority was added.
  • python3 scripts/check_architecture.py --base <PR-base-commit> passes; budgets were not inflated to fit the change.
  • Tests cover success and failure; platform/feature coverage limitations are stated.
  • New messages: N/A — no user-visible strings added.
  • Governance: N/A — no governance change.

The cursor anchor counted blank logical lines and treated the start of a
wrapped line below the cursor as the anchor itself. Narrowing across a wrap
boundary therefore moved the cursor one logical line down per drag tick (or
left it on the wrong row), so later cursor-relative repaints landed off the
prompt.

Anchor by non-empty logical lines only: reflow drops blank rows, while
non-empty lines keep their identity and order. Restore the cursor to the
same logical line and column across every intermediate width.

Regression test covers a scrolled-back grid through 80 to 40 and back.

Refs Kuddev#1091.
@not-exist
not-exist requested a review from Kuddev as a code owner November 24, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant