fix: any_file and any_dir should check is_folder

This commit is contained in:
sxyazi 2024-02-20 17:45:41 +08:00
parent 8efafd6c91
commit 2e9b6b7b7b
No known key found for this signature in database
5 changed files with 11 additions and 14 deletions

View file

@ -37,10 +37,10 @@ impl Pattern {
}
#[inline]
pub fn any_file(&self) -> bool { self.inner.as_str() == "*" }
pub fn any_file(&self) -> bool { !self.is_folder && self.inner.as_str() == "*" }
#[inline]
pub fn any_dir(&self) -> bool { self.inner.as_str() == "*/" }
pub fn any_dir(&self) -> bool { self.is_folder && self.inner.as_str() == "*" }
}
impl TryFrom<&str> for Pattern {

View file

@ -34,12 +34,6 @@ impl Default for Plugin {
}
let mut shadow = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().plugin;
if shadow.append_preloaders.iter().any(|r| r.any_file()) {
shadow.preloaders.retain(|r| !r.any_file());
}
if shadow.append_preloaders.iter().any(|r| r.any_dir()) {
shadow.preloaders.retain(|r| !r.any_dir());
}
if shadow.append_previewers.iter().any(|r| r.any_file()) {
shadow.previewers.retain(|r| !r.any_file());
}

View file

@ -42,6 +42,10 @@ impl TryFrom<Cmd> for Message {
impl Message {
#[inline]
pub fn height(&self, width: u16) -> usize {
if width == 0 {
return 0; // In case we can't get the width of the terminal
}
let lines = (self.content.width() as f64 / width as f64).ceil();
lines as usize + NOTIFY_BORDER as usize
}

View file

@ -2,12 +2,13 @@ use crossterm::terminal::WindowSize;
use ratatui::layout::Rect;
use yazi_shared::{event::Cmd, term::Term};
use crate::app::App;
use crate::{app::App, notify};
impl App {
pub(crate) fn update_notify(&mut self, cmd: Cmd) {
let WindowSize { width, height, .. } = Term::size();
let area = crate::notify::Layout::available(Rect { x: 0, y: 0, width, height });
let WindowSize { rows, columns, .. } = Term::size();
let area =
notify::Layout::available(Rect { x: 0, y: 0, width: columns, height: rows });
self.cx.notify.tick(cmd, area);

View file

@ -71,9 +71,7 @@ impl File {
Ok(THEME.filetypes.iter().find(|&x| x.matches(me, mime)).map(|x| Style::from(x.style)))
});
reg.add_method("is_hovered", |_, me, ()| {
Ok(matches!(me.folder().hovered(), Some(f) if f.url == me.url))
});
reg.add_method("is_hovered", |_, me, ()| Ok(me.idx == me.folder().cursor));
reg.add_method("is_yanked", |lua, me, ()| {
let cx = lua.named_registry_value::<CtxRef>("cx")?;
Ok(if !cx.manager.yanked.contains(&me.url) {