docs(view): say why the prompt editor's row unwraps cannot fail

`lines.last_mut().unwrap()` appears six times while laying out the
inline editor, the furthest of them seventy lines from the thing that
makes it safe: `lines` is seeded with one row and rows are only ever
pushed. A reader meeting the unwrap first has to go looking, and a
reader adding a `pop` or a `drain` has nothing to warn them.

Found by sweeping the tree for panicking arithmetic and unwraps rather
than by anything failing. Everything else that sweep turned up is
already guarded, and the guards are worth recording as checked:

- `heal_active` in tree_sync returns early on an empty tab list before
  `tabs.len() - 1`, matching the `ActiveTabChanged` contract that a
  workspace with no tabs simply has no active tab.
- The scrollback ring's `bytes[bytes.len() - RING_CAP..]` sits behind
  `if bytes.len() >= RING_CAP`, and its neighbours use saturating adds.
- The tab-title eliders bound every head against `cells.len()` before
  subtracting, and the binary search's `mid - 1` cannot underflow
  because `mid` is at least 1 whenever `lo < hi`.
This commit is contained in:
l0ng-ai
2026-08-16 08:39:52 +08:00
parent a98cd7bb37
commit 4e427d9b7e
+4
View File
@@ -5508,6 +5508,10 @@ impl TerminalView {
let blank = move |w: gpui::Pixels| div().flex_none().w(w).h(lh);
// Seeded with one row, and rows are only ever pushed — never popped or
// drained. That is what makes the `lines.last_mut().unwrap()` below
// safe, several of them a long way from here: there is always a row to
// append to, including before the first newline is seen.
let mut lines: Vec<Vec<gpui::AnyElement>> =
vec![vec![blank(cell_w * (ccol as f32)).into_any_element()]];