mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: tab-specific sorting (#131)
This commit is contained in:
parent
cad6560955
commit
1a1dd9c355
5 changed files with 33 additions and 29 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::{collections::{BTreeMap, BTreeSet}, mem, ops::Deref, sync::atomic::Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use config::manager::SortBy;
|
||||
use config::{manager::SortBy, MANAGER};
|
||||
use shared::Url;
|
||||
use tokio::{fs, select, sync::mpsc::{self, UnboundedReceiver}};
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ impl Default for Files {
|
|||
selected: Default::default(),
|
||||
|
||||
sorter: Default::default(),
|
||||
show_hidden: true,
|
||||
show_hidden: MANAGER.show_hidden,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -244,7 +244,6 @@ impl Files {
|
|||
#[inline]
|
||||
pub fn sorter(&self) -> &FilesSorter { &self.sorter }
|
||||
|
||||
#[inline]
|
||||
pub fn set_sorter(&mut self, sorter: FilesSorter) -> bool {
|
||||
if self.sorter == sorter {
|
||||
return false;
|
||||
|
|
@ -255,7 +254,6 @@ impl Files {
|
|||
}
|
||||
|
||||
// --- Show hidden
|
||||
#[inline]
|
||||
pub fn set_show_hidden(&mut self, state: bool) -> bool {
|
||||
if state == self.show_hidden {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use shared::Url;
|
|||
|
||||
use super::File;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct FilesSorter {
|
||||
pub by: SortBy,
|
||||
pub reverse: bool,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl Manager {
|
|||
pub fn refresh(&mut self) {
|
||||
env::set_current_dir(self.cwd()).ok();
|
||||
|
||||
self.active_mut().apply_show_hidden(false);
|
||||
self.active_mut().apply_files_attrs(false);
|
||||
|
||||
if let Some(f) = self.parent() {
|
||||
self.watcher.trigger_dirs(&[self.cwd(), &f.cwd]);
|
||||
|
|
@ -339,7 +339,7 @@ impl Manager {
|
|||
self.active_mut().parent.as_mut().unwrap().update(op)
|
||||
} else if matches!(self.hovered(), Some(h) if h.url() == &url) {
|
||||
self.active_mut().history.entry(url.clone()).or_insert_with(|| Folder::from(&url));
|
||||
self.active_mut().apply_show_hidden(true);
|
||||
self.active_mut().apply_files_attrs(true);
|
||||
self.active_mut().history.get_mut(&url).unwrap().update(op)
|
||||
} else {
|
||||
self.active_mut().history.entry(url.clone()).or_insert_with(|| Folder::from(&url)).update(op);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{borrow::Cow, collections::{BTreeMap, BTreeSet}, ffi::{OsStr, OsString}, mem, time::Duration};
|
||||
|
||||
use anyhow::{bail, Error, Result};
|
||||
use config::{keymap::{Exec, KeymapLayer}, open::Opener};
|
||||
use config::{keymap::{Exec, KeymapLayer}, open::Opener, MANAGER};
|
||||
use shared::{Debounce, Defer, InputError, Url};
|
||||
use tokio::{pin, task::JoinHandle};
|
||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||
|
|
@ -19,6 +19,7 @@ pub struct Tab {
|
|||
|
||||
finder: Option<Finder>,
|
||||
search: Option<JoinHandle<Result<()>>>,
|
||||
pub(super) sorter: FilesSorter,
|
||||
pub(super) show_hidden: bool,
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +37,8 @@ impl From<Url> for Tab {
|
|||
|
||||
finder: None,
|
||||
search: None,
|
||||
show_hidden: true,
|
||||
sorter: Default::default(),
|
||||
show_hidden: MANAGER.show_hidden,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -465,12 +467,12 @@ impl Tab {
|
|||
|
||||
// --- Sorter
|
||||
pub fn set_sorter(&mut self, sorter: FilesSorter) -> bool {
|
||||
if !self.current.files.set_sorter(sorter) {
|
||||
if sorter == self.sorter {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.current.hover_repos();
|
||||
true
|
||||
self.sorter = sorter;
|
||||
self.apply_files_attrs(false)
|
||||
}
|
||||
|
||||
// --- Show hidden
|
||||
|
|
@ -481,26 +483,32 @@ impl Tab {
|
|||
}
|
||||
|
||||
self.show_hidden = state;
|
||||
self.apply_show_hidden(false);
|
||||
true
|
||||
self.apply_files_attrs(false)
|
||||
}
|
||||
|
||||
pub fn apply_show_hidden(&mut self, only_hovered: bool) -> bool {
|
||||
let state = self.show_hidden;
|
||||
let mut b = match self.current.hovered {
|
||||
Some(ref h) if h.is_dir() => {
|
||||
self.history.get_mut(h.url()).map(|f| f.files.set_show_hidden(state)) == Some(true)
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
pub fn apply_files_attrs(&mut self, only_hovered: bool) -> bool {
|
||||
let mut b = false;
|
||||
if let Some(f) = self
|
||||
.current
|
||||
.hovered
|
||||
.as_ref()
|
||||
.filter(|h| h.is_dir())
|
||||
.and_then(|h| self.history.get_mut(h.url()))
|
||||
{
|
||||
b |= f.files.set_show_hidden(self.show_hidden);
|
||||
b |= f.files.set_sorter(self.sorter);
|
||||
}
|
||||
|
||||
if only_hovered {
|
||||
return b;
|
||||
}
|
||||
|
||||
b |= self.current.files.set_show_hidden(state);
|
||||
b |= self.current.files.set_show_hidden(self.show_hidden);
|
||||
b |= self.current.files.set_sorter(self.sorter);
|
||||
|
||||
if let Some(parent) = self.parent.as_mut() {
|
||||
b |= parent.files.set_show_hidden(state);
|
||||
b |= parent.files.set_show_hidden(self.show_hidden);
|
||||
b |= parent.files.set_sorter(self.sorter);
|
||||
}
|
||||
|
||||
self.current.hover_repos();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use config::{BOOT, MANAGER};
|
||||
use config::BOOT;
|
||||
use shared::Url;
|
||||
|
||||
use super::Tab;
|
||||
|
|
@ -13,10 +13,7 @@ pub struct Tabs {
|
|||
|
||||
impl Tabs {
|
||||
pub fn make() -> Self {
|
||||
let mut tab = Tab::from(Url::from(&BOOT.cwd));
|
||||
tab.set_show_hidden(Some(MANAGER.show_hidden));
|
||||
|
||||
let mut tabs = Self { idx: usize::MAX, items: vec![tab] };
|
||||
let mut tabs = Self { idx: usize::MAX, items: vec![Tab::from(Url::from(&BOOT.cwd))] };
|
||||
tabs.set_idx(0);
|
||||
tabs
|
||||
}
|
||||
|
|
@ -28,6 +25,7 @@ impl Tabs {
|
|||
|
||||
let mut tab = Tab::from(url);
|
||||
tab.set_show_hidden(Some(self.active().show_hidden));
|
||||
tab.set_sorter(self.active().sorter);
|
||||
|
||||
self.items.insert(self.idx + 1, tab);
|
||||
self.set_idx(self.idx + 1);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue