mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
perf: clear only limited cells when hiding images (#369)
This commit is contained in:
parent
f038391ef5
commit
24e92d09e5
3 changed files with 24 additions and 12 deletions
|
|
@ -4,7 +4,7 @@ use ratatui::{prelude::Rect, widgets::{Block, Padding}};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use yazi_shared::Term;
|
use yazi_shared::Term;
|
||||||
|
|
||||||
use crate::THEME;
|
use crate::{PREVIEW, THEME};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
#[serde(try_from = "Vec<u16>")]
|
#[serde(try_from = "Vec<u16>")]
|
||||||
|
|
@ -38,22 +38,34 @@ impl TryFrom<Vec<u16>> for ManagerLayout {
|
||||||
impl ManagerLayout {
|
impl ManagerLayout {
|
||||||
pub fn preview_rect(&self) -> Rect {
|
pub fn preview_rect(&self) -> Rect {
|
||||||
let WindowSize { columns, rows, .. } = Term::size();
|
let WindowSize { columns, rows, .. } = Term::size();
|
||||||
|
let (top, right, bottom, left) = THEME.manager.preview_offset;
|
||||||
|
|
||||||
let width = (columns * self.preview) as f64 / self.all as f64;
|
let w = (columns * self.preview) as f64 / self.all as f64;
|
||||||
let width = if width.fract() > 0.5 { width.ceil() as u16 } else { width.floor() as u16 };
|
let w = if w.fract() > 0.5 { w.ceil() as u16 } else { w.floor() as u16 };
|
||||||
|
|
||||||
let offset = THEME.manager.preview_offset;
|
Rect {
|
||||||
Block::default().padding(Padding::new(offset.3, offset.1, offset.0, offset.2)).inner(Rect {
|
x: left.saturating_add(columns - w),
|
||||||
x: columns.saturating_sub(width),
|
y: top,
|
||||||
y: 0,
|
width: w.saturating_sub(left + right),
|
||||||
width,
|
height: rows.saturating_sub(top + bottom),
|
||||||
height: rows,
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn preview_height(&self) -> usize { self.preview_rect().height as usize }
|
pub fn preview_height(&self) -> usize { self.preview_rect().height as usize }
|
||||||
|
|
||||||
|
pub fn image_rect(&self) -> Rect {
|
||||||
|
let mut rect = self.preview_rect();
|
||||||
|
if PREVIEW.max_width == 0 || PREVIEW.max_height == 0 {
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
if let Some((w, h)) = Term::ratio() {
|
||||||
|
rect.width = rect.width.min((PREVIEW.max_width as f64 / w).ceil() as u16);
|
||||||
|
rect.height = rect.height.min((PREVIEW.max_height as f64 / h).ceil() as u16);
|
||||||
|
}
|
||||||
|
rect
|
||||||
|
}
|
||||||
|
|
||||||
pub fn folder_rect(&self) -> Rect {
|
pub fn folder_rect(&self) -> Rect {
|
||||||
let WindowSize { columns, rows, .. } = Term::size();
|
let WindowSize { columns, rows, .. } = Term::size();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ impl Preview {
|
||||||
pub fn reset<F: FnOnce(&PreviewLock) -> bool>(&mut self, f: F) -> bool {
|
pub fn reset<F: FnOnce(&PreviewLock) -> bool>(&mut self, f: F) -> bool {
|
||||||
self.handle.take().map(|h| h.abort());
|
self.handle.take().map(|h| h.abort());
|
||||||
Highlighter::abort();
|
Highlighter::abort();
|
||||||
ADAPTOR.image_hide(MANAGER.layout.preview_rect()).ok();
|
ADAPTOR.image_hide(MANAGER.layout.image_rect()).ok();
|
||||||
|
|
||||||
let Some(ref lock) = self.lock else {
|
let Some(ref lock) = self.lock else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ impl Provider {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn image(path: &Path) -> Result<PreviewData, PeekError> {
|
pub(super) async fn image(path: &Path) -> Result<PreviewData, PeekError> {
|
||||||
ADAPTOR.image_show(path, MANAGER.layout.preview_rect()).await?;
|
ADAPTOR.image_show(path, MANAGER.layout.image_rect()).await?;
|
||||||
Ok(PreviewData::Image)
|
Ok(PreviewData::Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue