Skip to content

refactor(painter): record a resize as a cursor row, not a prompt row - #1213

Open
kronberger-droid wants to merge 1 commit into
nushell:mainfrom
kronberger-droid:fix/painter-resize-anchor
Open

refactor(painter): record a resize as a cursor row, not a prompt row#1213
kronberger-droid wants to merge 1 commit into
nushell:mainfrom
kronberger-droid:fix/painter-resize-anchor

Conversation

@kronberger-droid

Copy link
Copy Markdown
Collaborator

Summary

handle_resize stores the cursor row in prompt_start_row, which everywhere else holds the row the prompt starts on, and a just_resized bool told the two apart.
Every path that writes the row has to keep that bool in step, and anchor_prompt, clear_screen and print_external_message all write it without touching the flag, so a resize whose paint never came leaves a later paint subtracting from a row that was already a prompt row.

A Resized { cursor_row } variant makes that unrepresentable, since the state itself says which row it holds.

No public API change, PromptStartRow and its methods are all pub(crate).

After

enum PromptStartRow {
    Unverified,
    Stale(u16),
    Resized { cursor_row: u16 },
    Verified(u16),
}

repaint_buffer resolves it with resolve_resize(lines_before_cursor) where the old block was, and just_resized is gone.

The resolved row is Verified rather than Stale, thus one cursor::position() per resize goes away.
That query fed the drift check, which re-anchors only when the measured cursor sits above the cached row, and a row reached by subtracting from that same cursor never is, so it could not change the answer.

`prompt_start_row` held a cursor row whenever `just_resized` was set, so
any path that rewrote the row without clearing the flag (`anchor_prompt`,
`clear_screen`, `print_external_message`) left the next paint subtracting
from a row that was already a prompt row. `Resized` carries the cursor row
in the state itself, thus the two cannot come apart.

The resolved row is now `Verified`, which drops one `cursor::position()`
per resize. The drift check that query fed re-anchors only when the cursor
sits above the cached row, and a row reached by subtracting from that same
cursor never does, so the answer could not change.
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