fix(erase_last_command): erase the most recent command even empty output - #10201
Merged
kovidgoyal merged 1 commit intoJun 29, 2026
Merged
kovidgoyal merged 1 commit into
kovidgoyal merged 1 commit into
Conversation
erase_last_command selected the region to erase via find_cmd_output(..., -1), which anchors on OUTPUT_START (OSC, 133;C). Commands that produce no output (an empty Enter, a comment, cd, export, etc. -- never emit 133;C, so they were skipped and an older command-with-output was erased instead. "Erase the last command" therefore did not erase the last command whenever the most recent ones has no output. Select the region by prompt marks instead: erase the prompt block immediately above the current (live) prompt, whatever it contains. Every submittd command is now one unit, removed newest-first, one prompt block per invocation. This also fixes two latent defects in the previous implementation: * The on-screen deletion was anchored at `cursor->y - count`, which assumes the region ends exactly one row above the cursor. Multi-line prompts and skipped rows broke that assumption and left residual lines. Anchor at the top of the region instead. * When part of the erased region was in the scrollback, the lines were removed from the history buffer but no redraw was signalled, so the deletion of the off-screen lines only became visible after the next scroll event recomputed the history viewport. Clamp scrolled_by to the new history length and call dirty_scroll() after shrinking the buffer. include_prompt is retained for API compatibility but is now a no-op: the unit erased is always the whole prompt block.
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.
erase_last_command(theclear_terminal last_commandaction) located the region to erase withfind_cmd_output(..., -1), which anchors onOUTPUT_START(OSC 133;C). A prompt block with no command output -- a command that prints nothing (cd,export, a comment) or no command at all (a bare Enter) -- has noOUTPUT_START, so the search does have output. It therefore erases an older block instead of the most recent one.This PR selects the region by prompt marks instead: it erases the prompt block immediately above the live prompt, newest-first, one block per keypress. If no block sits above the live prompt, it does nothing. It also fixes two pre-existing problems on the same path:
cursor->y - count, which assumes the region ends one row above the cursor. Multi-line prompts (and rows above the region) break that, leaving residual lines; it now anchors at the top of the region.scrolled_byand callsdirty_scroll(), asscreen_clear_scrollbackdoes.include_promptremains for API compatibility but now does nothing (the unit is the whole prompt block; no in-tree caller passes it).