mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
4b98c65559
commit
9d1c5041fd
6 changed files with 70 additions and 32 deletions
|
|
@ -117,11 +117,13 @@ impl Executor {
|
|||
exec.named.contains_key("block"),
|
||||
exec.named.contains_key("confirm"),
|
||||
),
|
||||
"hidden" => cx.manager.current_mut().hidden(match exec.args.get(0).map(|s| s.as_str()) {
|
||||
Some("show") => Some(true),
|
||||
Some("hide") => Some(false),
|
||||
_ => None,
|
||||
}),
|
||||
"hidden" => {
|
||||
cx.manager.active_mut().set_show_hidden(match exec.args.get(0).map(|s| s.as_str()) {
|
||||
Some("show") => Some(true),
|
||||
Some("hide") => Some(false),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
"search" => match exec.args.get(0).map(|s| s.as_str()).unwrap_or("") {
|
||||
"rg" => cx.manager.active_mut().search(true),
|
||||
"fd" => cx.manager.active_mut().search(false),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use std::{collections::{BTreeMap, BTreeSet}, mem, ops::Deref, path::{Path, PathBuf}};
|
||||
|
||||
use anyhow::Result;
|
||||
use config::MANAGER;
|
||||
use tokio::fs;
|
||||
|
||||
use super::{File, FilesSorter};
|
||||
|
|
@ -27,7 +26,7 @@ impl Default for Files {
|
|||
selected: Default::default(),
|
||||
|
||||
sorter: Default::default(),
|
||||
show_hidden: MANAGER.show_hidden,
|
||||
show_hidden: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -211,11 +210,7 @@ impl Files {
|
|||
|
||||
// --- Show hidden
|
||||
#[inline]
|
||||
pub fn show_hidden(&self) -> bool { self.show_hidden }
|
||||
|
||||
#[inline]
|
||||
pub fn set_show_hidden(&mut self, state: Option<bool>) -> bool {
|
||||
let state = state.unwrap_or(!self.show_hidden);
|
||||
pub fn set_show_hidden(&mut self, state: bool) -> bool {
|
||||
if state == self.show_hidden {
|
||||
return false;
|
||||
} else if state && self.hidden.is_empty() {
|
||||
|
|
|
|||
|
|
@ -92,13 +92,6 @@ impl Folder {
|
|||
old != self.cursor
|
||||
}
|
||||
|
||||
pub fn hidden(&mut self, show: Option<bool>) -> bool {
|
||||
if self.files.set_show_hidden(show) {
|
||||
emit!(Refresh);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn window(&self) -> &[File] {
|
||||
let end = (self.offset + MANAGER.layout.folder_height()).min(self.files.len());
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ impl Manager {
|
|||
pub fn refresh(&mut self) {
|
||||
env::set_current_dir(self.cwd()).ok();
|
||||
|
||||
self.active_mut().apply_show_hidden();
|
||||
|
||||
if let Some(f) = self.parent() {
|
||||
self.watcher.trigger_dirs(&[self.cwd(), &f.cwd]);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@ pub struct Tab {
|
|||
pub(super) current: Folder,
|
||||
pub(super) parent: Option<Folder>,
|
||||
|
||||
search: Option<JoinHandle<Result<()>>>,
|
||||
|
||||
pub(super) history: BTreeMap<PathBuf, Folder>,
|
||||
pub(super) preview: Preview,
|
||||
|
||||
search: Option<JoinHandle<Result<()>>>,
|
||||
pub(super) show_hidden: bool,
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
|
|
@ -27,10 +28,11 @@ impl Tab {
|
|||
current: Folder::new(path),
|
||||
parent: path.parent().map(Folder::new),
|
||||
|
||||
search: None,
|
||||
|
||||
history: Default::default(),
|
||||
preview: Default::default(),
|
||||
|
||||
search: None,
|
||||
show_hidden: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +232,7 @@ impl Tab {
|
|||
}
|
||||
|
||||
let cwd = self.current.cwd.clone();
|
||||
let hidden = self.current.files.show_hidden();
|
||||
let hidden = self.show_hidden;
|
||||
|
||||
self.search = Some(tokio::spawn(async move {
|
||||
let subject = emit!(Input(InputOpt::top("Search:"))).await?;
|
||||
|
|
@ -347,9 +349,16 @@ impl Tab {
|
|||
}
|
||||
|
||||
impl Tab {
|
||||
// --- Mode
|
||||
#[inline]
|
||||
pub fn mode(&self) -> &Mode { &self.mode }
|
||||
|
||||
#[inline]
|
||||
pub fn in_selecting(&self) -> bool {
|
||||
self.mode().is_visual() || self.current.files.has_selected()
|
||||
}
|
||||
|
||||
// --- Current
|
||||
#[inline]
|
||||
pub fn name(&self) -> &str {
|
||||
self
|
||||
|
|
@ -373,11 +382,7 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn in_selecting(&self) -> bool {
|
||||
self.mode().is_visual() || self.current.files.has_selected()
|
||||
}
|
||||
|
||||
// --- History
|
||||
#[inline]
|
||||
pub fn history(&self, path: &Path) -> Option<&Folder> { self.history.get(path) }
|
||||
|
||||
|
|
@ -386,6 +391,7 @@ impl Tab {
|
|||
self.history.remove(path).unwrap_or_else(|| Folder::new(path))
|
||||
}
|
||||
|
||||
// --- Preview
|
||||
#[inline]
|
||||
pub fn preview(&self) -> &Preview { &self.preview }
|
||||
|
||||
|
|
@ -394,4 +400,38 @@ impl Tab {
|
|||
|
||||
#[inline]
|
||||
pub fn preview_reset_image(&mut self) -> bool { self.preview.reset_image() }
|
||||
|
||||
// --- Show hidden
|
||||
pub fn set_show_hidden(&mut self, state: Option<bool>) -> bool {
|
||||
let state = state.unwrap_or(!self.show_hidden);
|
||||
if state == self.show_hidden {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.show_hidden = state;
|
||||
self.apply_show_hidden();
|
||||
true
|
||||
}
|
||||
|
||||
pub fn apply_show_hidden(&mut self) -> bool {
|
||||
let state = self.show_hidden;
|
||||
|
||||
let mut applied = false;
|
||||
applied |= self.current.files.set_show_hidden(state);
|
||||
|
||||
if let Some(parent) = self.parent.as_mut() {
|
||||
applied |= parent.files.set_show_hidden(state);
|
||||
}
|
||||
|
||||
applied |= match self.current.hovered {
|
||||
Some(ref hovered) if hovered.is_dir() => self
|
||||
.history
|
||||
.get_mut(hovered.path())
|
||||
.map(|f| f.files.set_show_hidden(state))
|
||||
.unwrap_or(false),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
applied
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::path::Path;
|
||||
|
||||
use config::BOOT;
|
||||
use config::{BOOT, MANAGER};
|
||||
|
||||
use super::Tab;
|
||||
use crate::emit;
|
||||
|
|
@ -14,7 +14,10 @@ pub struct Tabs {
|
|||
|
||||
impl Tabs {
|
||||
pub fn make() -> Self {
|
||||
let mut tabs = Self { idx: usize::MAX, items: vec![Tab::new(&BOOT.cwd)] };
|
||||
let mut tab = Tab::new(&BOOT.cwd);
|
||||
tab.set_show_hidden(Some(MANAGER.show_hidden));
|
||||
|
||||
let mut tabs = Self { idx: usize::MAX, items: vec![tab] };
|
||||
tabs.set_idx(0);
|
||||
tabs
|
||||
}
|
||||
|
|
@ -24,7 +27,10 @@ impl Tabs {
|
|||
return false;
|
||||
}
|
||||
|
||||
self.items.insert(self.idx + 1, Tab::new(path));
|
||||
let mut tab = Tab::new(path);
|
||||
tab.set_show_hidden(Some(self.active().show_hidden));
|
||||
|
||||
self.items.insert(self.idx + 1, tab);
|
||||
self.set_idx(self.idx + 1);
|
||||
true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue