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