fix(tui/image): init picker for image cards

This commit is contained in:
James Peter
2026-01-07 12:04:41 +10:00
parent 7369620a60
commit 63e53af9b9
2 changed files with 42 additions and 3 deletions
+19 -3
View File
@@ -9251,6 +9251,17 @@ impl ChatWidget<'_> {
layout_scroll::flash_scrollbar(self);
}
fn ensure_image_cell_picker(&self, cell: &dyn HistoryCell) {
if let Some(image) = cell
.as_any()
.downcast_ref::<crate::history_cell::ImageOutputCell>()
{
let picker = self.terminal_info.picker.clone();
let font_size = self.terminal_info.font_size;
image.ensure_picker_initialized(picker, font_size);
}
}
fn history_insert_with_key_global(
&mut self,
cell: Box<dyn HistoryCell>,
@@ -9278,6 +9289,7 @@ impl ChatWidget<'_> {
);
}
}
self.ensure_image_cell_picker(cell.as_ref());
// Any ordered insert of a non-reasoning cell means reasoning is no longer the
// bottom-most active block; drop the in-progress ellipsis on collapsed titles.
let is_reasoning_cell = cell
@@ -10006,9 +10018,11 @@ impl ChatWidget<'_> {
HistoryRecord::BackgroundEvent(state) => {
Some(Box::new(history_cell::BackgroundEventCell::new(state.clone())))
}
HistoryRecord::Image(state) => Some(Box::new(
history_cell::ImageOutputCell::from_record(state.clone()),
)),
HistoryRecord::Image(state) => {
let cell = history_cell::ImageOutputCell::from_record(state.clone());
self.ensure_image_cell_picker(&cell);
Some(Box::new(cell))
}
HistoryRecord::Context(state) => Some(Box::new(
history_cell::ContextCell::new(state.clone()),
)),
@@ -10397,6 +10411,7 @@ impl ChatWidget<'_> {
}
}
self.ensure_image_cell_picker(cell.as_ref());
self.history_cells[idx] = cell;
self.invalidate_height_cache();
self.request_redraw();
@@ -10445,6 +10460,7 @@ impl ChatWidget<'_> {
(None, None) => {}
}
self.ensure_image_cell_picker(cell.as_ref());
self.history_cells[idx] = cell;
if idx < self.history_cell_ids.len() {
self.history_cell_ids[idx] = maybe_id;
+23
View File
@@ -72,6 +72,29 @@ impl ImageOutputCell {
Self::new(record)
}
pub(crate) fn ensure_picker_initialized(
&self,
picker: Option<Picker>,
font_size: (u16, u16),
) {
let mut slot = self.cached_picker.borrow_mut();
let needs_init = match slot.as_ref() {
None => true,
Some(existing) => {
if let Some(provided) = picker.as_ref() {
existing.font_size() != provided.font_size()
|| existing.protocol_type() != provided.protocol_type()
} else {
existing.font_size() != font_size
}
}
};
if needs_init {
*slot = Some(picker.unwrap_or_else(|| Picker::from_fontsize(font_size)));
self.cached_image_protocol.borrow_mut().take();
}
}
pub(crate) fn record(&self) -> &ImageRecord {
&self.record
}