ZIm/crates/terminal_view/src
Cole Miller af0031ae8b
Fix positioning of terminal inline assist after clearing the screen (#34465)
Closes #33945. Here's my attempt to describe what's going on in that
issue and what this fix is doing:

We always render the terminal inline assistant starting on the line
after the cursor, with a height of 4 lines. When deploying it, we scroll
the viewport to the bottom of the terminal so that the assistant will be
in view.

When scrolling while the assistant is deployed (including in that case),
we need to make an adjustment that "pushes up" the terminal content by
the height of the assistant, so that we can scroll to see all the normal
content plus the assistant itself. That quantity is `scroll_top`, which
represents _how much height in the current viewport is occupied by the
assistant that would otherwise be occupied by terminal content_. So when
you scroll up and a line of the assistant's height goes out of view,
`scroll_top` decreases by 1, etc.

When we scroll to the bottom after deploying the assistant, we set
`scroll_top` to the result of calling `max_scroll_top`, which computes
it this way:

```
block.height.saturating_sub(viewport_lines.saturating_sub(terminal_lines))
```

Which, being interpreted, is "the height of the assistant, minus any
viewport lines that are not occupied by terminal content", i.e. the
assistant is allowed to eat up vertical space below the last line of
terminal content without increasing `scroll_top`.

The problem comes when we clear the screen---this adds a full screen to
`terminal_lines`, but the cursor is positioned at the top of the
viewport with blank lines below, just like at the beginning of a session
when `terminal_lines == 1`. Those blank lines should be available to the
assistant, but the `scroll_top` calculation doesn't reflect that.

I've tried to fix this by basing the `max_scroll_top` calculation on the
position of the cursor instead of the raw `terminal_lines` value. There
was also a special case for `viewport_lines == terminal_lines` that I
think can now be removed.

Release Notes:

- Fixed the positioning of the terminal inline assistant when it's
deployed after clearing the terminal.
2025-07-15 15:16:48 -04:00
..
color_contrast.rs Automatically adjust ANSI color contrast (#34033) 2025-07-07 22:39:11 +00:00
persistence.rs agent: Display full terminal output without scrolling (#31922) 2025-06-03 10:54:25 -07:00
terminal_element.rs Fix contrast adjustment for Powerline separators (#34417) 2025-07-14 18:18:41 +00:00
terminal_panel.rs Refine status bar design (#34324) 2025-07-12 11:48:19 -03:00
terminal_scrollbar.rs Reapply "ui: Account for padding of parent container during scrollbar layout" (#30577) 2025-05-14 13:26:14 +02:00
terminal_slash_command.rs chore: Make terminal_view own the TerminalSlashCommand (#31070) 2025-05-21 09:27:54 +00:00
terminal_tab_tooltip.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
terminal_view.rs Fix positioning of terminal inline assist after clearing the screen (#34465) 2025-07-15 15:16:48 -04:00