Broaden anchor-window clamp to CUP-park on empty trailing row (#157)#159
Merged
Broaden anchor-window clamp to CUP-park on empty trailing row (#157)#159
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression variant of the anchor-window scroll/clamp behavior (#157) by expanding the clamp guard beyond pending-wrap to also handle TUIs that CUP-position the cursor onto an empty trailing row, which can otherwise leave pt == point-max and trigger redisplay to scroll window-start.
Changes:
- Add a native render helper (
render.isRowEmptyAt) and new exported module predicateghostel--cursor-on-empty-row-p. - Broaden
ghostel--anchor-window’s clamp condition to(or pending-wrap cursor-on-empty-row). - Add ERT coverage for the new predicate and for the #157 clamp/no-clamp scenarios; bump module/package version to 0.16.3.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
ghostel.el |
Expands the clamp condition in ghostel--anchor-window and updates module version/min-version + function declaration. |
src/render.zig |
Implements isRowEmptyAt to detect rows that would render as empty buffer lines. |
src/module.zig |
Exports ghostel--cursor-on-empty-row-p and bumps native module version. |
src/ghostty.zig |
Adds DATA_CURSOR_Y constant binding used by the new predicate. |
test/ghostel-test.el |
Adds unit/regression tests for empty-row predicate and anchor-window clamp behavior. |
build.zig.zon |
Bumps package version to 0.16.3. |
evil-ghostel.el |
Bumps package version to 0.16.3. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dakra
added a commit
that referenced
this pull request
Apr 20, 2026
Addresses Copilot review on #159. `isRowEmptyAt' iterates the render state's viewport row iterator, so `cy' should come from the same coordinate space. `DATA_CURSOR_Y' is active-area-relative and happens to match viewport Y in the common case (viewport pinned to bottom by redraw), but the render-state pair exposes a `HAS_VALUE' flag that correctly returns nil when the cursor isn't visible in the current viewport — which is also the safe answer for the anchor-window clamp. Move `render_state_update' to `fnCursorOnEmptyRow' and drop the redundant call inside `isRowEmptyAt'; update the helper docstring to state the caller contract. Remove the now-unused `DATA_CURSOR_Y' constant.
ad8536e narrowed the `ghostel--anchor-window' clamp to fire only when libghostty reports pending-wrap, which fixed the #146 regression but reopened a variant of #138 for TUIs that move their cursor to the bottom of the screen via absolute positioning (CUP) rather than via writing-then-wrapping. In that case `pt' equals `point-max' and the cursor sits on the last viewport row, but pending-wrap is nil — so the clamp doesn't fire and Emacs shifts `window-start' by one row to make `pt' "visible," fighting the viewport pin. Expose a second terminal-side predicate `ghostel--cursor-on-empty-row-p' backed by a new `render.isRowEmptyAt' helper, and widen the clamp guard to `(or pending-wrap cursor-on-empty-row)'. The predicate returns t iff the row containing the cursor has no written cells and no cells with non-default styling — exactly the condition under which `buildRowContent' produces `byte_len == 0'. Wide-spacer-tail cells are skipped to mirror `buildRowContent' (defensive — in practice spacer tails always follow a wide grapheme). Source `cy' from `RS_DATA_CURSOR_VIEWPORT_Y' gated by `...HAS_VALUE' so the coordinate space matches the viewport row iterator that `isRowEmptyAt' walks, and the predicate returns nil when the cursor isn't visible in the current viewport. Caller owns the `ghostty_render_state_update' refresh so it only happens once per call. An earlier draft (#158) tried `pos-visible-in-window-p' but it reflects the previous redisplay rather than the just-pinned `window-start', and breaks in batch. The terminal-side predicate answers the real question — is there anything on this row to anchor `pt' to? — without consulting Emacs redisplay state. Bump module version to 0.16.3 (new exported function). Test changes: - `ghostel-test-cursor-on-empty-row-p' covers the predicate across fresh-terminal / post-write / post-CRLF / post-CUP cursor positions. - `ghostel-test-anchor-window-clamps-on-empty-row' is the #157 regression test: feeds "foo\r\nbar\r\n" to park the cursor on an empty last row, asserts PT lands at `point-max', pending-wrap is nil, empty-row is t, and the clamp fires. - `ghostel-test-anchor-window-no-clamp-on-populated-last-row' complements #146: cursor at `point-max' on a last row that does have content (e.g. a shell prompt) must NOT be clamped regardless of which predicate is consulted. Closes #157.
3b18124 to
d4fdc8e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the #157 variant of #138: TUIs that CUP-park their cursor onto an empty trailing row (e.g. Claude Code on focus loss per the reporter's evidence) hit the same `pt = point-max` / window-start-shift symptom that #138 fixed, but without pending-wrap — so the `ad8536e` clamp narrowing lets them through.
Adds a second terminal-side predicate `ghostel--cursor-on-empty-row-p` (backed by a new `render.isRowEmptyAt` helper) and broadens the `ghostel--anchor-window` clamp guard to `(or pending-wrap cursor-on-empty-row)`. Predicate returns t iff the cursor's row has no written cells and no non-default styling — exactly when `buildRowContent` produces `byte_len == 0`.
Why not `pos-visible-in-window-p` (the approach in the now-closed #158): it reflects the previous redisplay, not the `window-start` we just pinned under `inhibit-redisplay`, and returns nil in batch — breaks existing tests. Terminal-side predicate answers the question without needing redisplay state.
Module version bumped 0.16.2 → 0.16.3 (new exported function).
Test plan