chat: use ScrollPane widget for both draw functions

draw_conversation_pane and draw_pane now delegate all scroll
bookkeeping and rendering to the ScrollPane widget. The conversation
pane builds MarkedLine items (line + gutter marker), applies
selection highlighting, and passes them to the widget. The simpler
panes just pass lines directly.

Removed dead code from scroll_pane: BorrowedItem, scroll_to_bottom,
heights(), ensure_heights_for_lines — all superseded by the widget
doing the work internally through the ScrollItem trait.

Co-Authored-By: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
ProofOfConcept 2026-04-11 01:27:46 -04:00 committed by Kent Overstreet
parent ceaa66e30d
commit 2d6a68048c
2 changed files with 46 additions and 106 deletions

View file

@ -40,23 +40,6 @@ impl ScrollItem for Text<'static> {
}
}
/// A borrowed item: a line with an optional gutter span.
/// Useful for rendering from parallel slices (lines + markers).
pub struct BorrowedItem<'a> {
pub line: &'a Line<'a>,
pub gutter_span: Option<Span<'a>>,
}
impl<'a> ScrollItem for BorrowedItem<'a> {
fn content(&self) -> Text<'_> {
Text::from(self.line.clone())
}
fn gutter(&self) -> Option<Span<'_>> {
self.gutter_span.clone()
}
}
// ── State ──────────────────────────────────────────────────────
pub struct ScrollPaneState {
@ -106,11 +89,6 @@ impl ScrollPaneState {
}
}
pub fn scroll_to_bottom(&mut self) {
self.offset = self.max_offset();
self.pinned = false;
}
fn max_offset(&self) -> u16 {
self.total_visual.saturating_sub(self.viewport_height)
}
@ -126,11 +104,6 @@ impl ScrollPaneState {
self.heights.truncate(index);
}
/// Access cached heights (for mouse coordinate mapping).
pub fn heights(&self) -> &[u16] {
&self.heights
}
/// Convert a screen row (relative to viewport) to an item index and
/// column, given the content items for text extraction.
pub fn screen_to_item(&self, mouse_x: u16, mouse_y: u16, lines: &[Line<'_>]) -> Option<(usize, usize)> {
@ -162,15 +135,6 @@ impl ScrollPaneState {
});
}
/// Compute or update cached heights from raw Lines.
pub fn ensure_heights_for_lines(&mut self, lines: &[Line<'_>], text_width: u16) {
self.ensure_heights_inner(lines.len(), text_width, |i| {
Paragraph::new(lines[i].clone())
.wrap(Wrap { trim: false })
.line_count(text_width) as u16
});
}
fn ensure_heights_inner(&mut self, count: usize, text_width: u16, height_fn: impl Fn(usize) -> u16) {
if text_width == 0 {
return;