fix(tui): keep popups above terminal images
This commit is contained in:
1 parent
6e898b8c45
commit
992f15b082
4 files changed
+59
-23
No files matched your search
@@ -3,7 +3,7 @@
|
||||
// so each popup type only worries about its inner area.
|
||||
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
buffer::{Buffer, CellDiffOption},
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Style},
|
||||
text::{Line, Span},
|
||||
@@ -25,6 +25,18 @@ pub struct PopupFrame<'a> {
|
||||
|
||||
impl<'a> Widget for PopupFrame<'a> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let covered_image_cells = area
|
||||
.rows()
|
||||
.flat_map(|row| row.columns())
|
||||
.filter(|position| {
|
||||
buf.cell(*position).is_some_and(|cell| {
|
||||
matches!(cell.diff_option, CellDiffOption::Skip)
|
||||
|| matches!(cell.diff_option, CellDiffOption::ForcedWidth(_))
|
||||
&& cell.symbol().contains('\x1b')
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// clear first so the popup doesn't layer on top of whatever was underneath
|
||||
Clear.render(area, buf);
|
||||
|
||||
@@ -48,6 +60,19 @@ impl<'a> Widget for PopupFrame<'a> {
|
||||
let inner = block.inner(area);
|
||||
block.render(area, buf);
|
||||
(self.content)(inner, buf);
|
||||
|
||||
// External image protocols can repaint unchanged terminal cells. Ratatui's
|
||||
// AlwaysUpdate option keeps only the popup cells covering an image above it.
|
||||
for position in covered_image_cells {
|
||||
if let Some(cell) = buf.cell_mut(position)
|
||||
&& !matches!(
|
||||
cell.diff_option,
|
||||
CellDiffOption::Skip | CellDiffOption::ForcedWidth(_)
|
||||
)
|
||||
{
|
||||
cell.set_diff_option(CellDiffOption::AlwaysUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,3 +90,7 @@ pub fn render_summary(rows: &[(&str, &str)], area: Rect, buf: &mut Buffer) {
|
||||
.collect::<Vec<_>>();
|
||||
Paragraph::new(lines).render(area, buf);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../../tests/widgets/popups/base.rs"]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user