mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: increase the granularity of back/forward history navigation to make its behavior more sensible (#2720)
This commit is contained in:
parent
c53865788a
commit
ca96c5bd98
6 changed files with 44 additions and 8 deletions
|
|
@ -4,6 +4,11 @@ use crate::tab::Tab;
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
pub fn back(&mut self, _: CmdCow) {
|
pub fn back(&mut self, _: CmdCow) {
|
||||||
self.backstack.shift_backward().cloned().map(|u| self.cd(u));
|
if self.current.url.is_regular() {
|
||||||
|
self.backstack.push(&self.current.url);
|
||||||
|
}
|
||||||
|
if let Some(u) = self.backstack.shift_backward().cloned() {
|
||||||
|
self.cd((u, super::cd::OptSource::Back));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,14 @@ use crate::tab::Tab;
|
||||||
|
|
||||||
struct Opt {
|
struct Opt {
|
||||||
target: Url,
|
target: Url,
|
||||||
|
source: OptSource,
|
||||||
interactive: bool,
|
interactive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CmdCow> for Opt {
|
impl From<CmdCow> for Opt {
|
||||||
fn from(mut c: CmdCow) -> Self {
|
fn from(mut c: CmdCow) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
source: OptSource::Cd,
|
||||||
interactive: c.bool("interactive"),
|
interactive: c.bool("interactive"),
|
||||||
..Self::from(c.take_first_url().unwrap_or_default())
|
..Self::from(c.take_first_url().unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
@ -26,11 +28,15 @@ impl From<CmdCow> for Opt {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Url> for Opt {
|
impl From<Url> for Opt {
|
||||||
fn from(mut target: Url) -> Self {
|
fn from(target: Url) -> Self { Self::from((target, OptSource::Cd)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(Url, OptSource)> for Opt {
|
||||||
|
fn from((mut target, source): (Url, OptSource)) -> Self {
|
||||||
if target.is_regular() {
|
if target.is_regular() {
|
||||||
target = Url::from(expand_path(&target));
|
target = Url::from(expand_path(&target));
|
||||||
}
|
}
|
||||||
Self { target, interactive: false }
|
Self { target, source, interactive: false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +73,7 @@ impl Tab {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backstack
|
// Backstack
|
||||||
if opt.target.is_regular() {
|
if opt.source.big_jump() && opt.target.is_regular() {
|
||||||
self.backstack.push(&opt.target);
|
self.backstack.push(&opt.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,3 +114,19 @@ impl Tab {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- OptSource
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub(super) enum OptSource {
|
||||||
|
Cd,
|
||||||
|
Reveal,
|
||||||
|
Enter,
|
||||||
|
Leave,
|
||||||
|
Forward,
|
||||||
|
Back,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OptSource {
|
||||||
|
#[inline]
|
||||||
|
fn big_jump(self) -> bool { self == Self::Cd || self == Self::Reveal }
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ use crate::tab::Tab;
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
pub fn enter(&mut self, _: CmdCow) {
|
pub fn enter(&mut self, _: CmdCow) {
|
||||||
self.hovered().filter(|h| h.is_dir()).map(|h| h.url.to_regular()).map(|u| self.cd(u));
|
self
|
||||||
|
.hovered()
|
||||||
|
.filter(|h| h.is_dir())
|
||||||
|
.map(|h| h.url.to_regular())
|
||||||
|
.map(|u| self.cd((u, super::cd::OptSource::Enter)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@ use crate::tab::Tab;
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
pub fn forward(&mut self, _: CmdCow) {
|
pub fn forward(&mut self, _: CmdCow) {
|
||||||
self.backstack.shift_forward().cloned().map(|u| self.cd(u));
|
if self.current.url.is_regular() {
|
||||||
|
self.backstack.push(&self.current.url);
|
||||||
|
}
|
||||||
|
if let Some(u) = self.backstack.shift_forward().cloned() {
|
||||||
|
self.cd((u, super::cd::OptSource::Forward));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,6 @@ impl Tab {
|
||||||
.and_then(|h| h.url.parent_url())
|
.and_then(|h| h.url.parent_url())
|
||||||
.filter(|u| u != self.cwd())
|
.filter(|u| u != self.cwd())
|
||||||
.or_else(|| self.cwd().parent_url())
|
.or_else(|| self.cwd().parent_url())
|
||||||
.map(|u| self.cd(u.into_regular()));
|
.map(|u| self.cd((u.into_regular(), super::cd::OptSource::Leave)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ impl Tab {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.cd(parent.clone());
|
self.cd((parent.clone(), super::cd::OptSource::Reveal));
|
||||||
self.current.hover(child.as_urn());
|
self.current.hover(child.as_urn());
|
||||||
|
|
||||||
if !opt.no_dummy && self.hovered().is_none_or(|f| &child != f.urn()) {
|
if !opt.no_dummy && self.hovered().is_none_or(|f| &child != f.urn()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue