mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: cd on the initial creation of a tab should not be added to the backstack (#2842)
This commit is contained in:
parent
145349b0e6
commit
d55e002d5a
8 changed files with 43 additions and 32 deletions
|
|
@ -3,7 +3,7 @@ use yazi_macro::render;
|
|||
use yazi_proxy::AppProxy;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
|
||||
use crate::{mgr::Tabs, tab::Tab};
|
||||
use crate::{mgr::Tabs, tab::{Tab, commands::CdSource}};
|
||||
|
||||
const MAX_TABS: usize = 9;
|
||||
|
||||
|
|
@ -35,15 +35,15 @@ impl Tabs {
|
|||
|
||||
let mut tab = Tab::default();
|
||||
if !opt.current {
|
||||
tab.cd(opt.url);
|
||||
tab.cd((opt.url, CdSource::Tab));
|
||||
} else if let Some(h) = self.active().hovered() {
|
||||
tab.pref = self.active().pref.clone();
|
||||
tab.apply_files_attrs();
|
||||
tab.reveal(h.url.to_regular());
|
||||
tab.reveal((h.url.to_regular(), CdSource::Tab));
|
||||
} else {
|
||||
tab.pref = self.active().pref.clone();
|
||||
tab.apply_files_attrs();
|
||||
tab.cd(self.active().cwd().to_regular());
|
||||
tab.cd((self.active().cwd().to_regular(), CdSource::Tab));
|
||||
}
|
||||
|
||||
self.items.insert(self.cursor + 1, tab);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use yazi_fs::File;
|
|||
use yazi_proxy::MgrProxy;
|
||||
use yazi_shared::{Id, url::Url};
|
||||
|
||||
use crate::tab::{Folder, Tab};
|
||||
use crate::tab::{Folder, Tab, commands::CdSource};
|
||||
|
||||
pub struct Tabs {
|
||||
pub cursor: usize,
|
||||
|
|
@ -21,9 +21,9 @@ impl Tabs {
|
|||
for (i, tab) in tabs.iter_mut().enumerate() {
|
||||
let file = &BOOT.files[i];
|
||||
if file.is_empty() {
|
||||
tab.cd(Url::from(&BOOT.cwds[i]));
|
||||
tab.cd((Url::from(&BOOT.cwds[i]), CdSource::Tab));
|
||||
} else {
|
||||
tab.reveal(Url::from(BOOT.cwds[i].join(file)));
|
||||
tab.reveal((Url::from(BOOT.cwds[i].join(file)), CdSource::Tab));
|
||||
}
|
||||
}
|
||||
tabs
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
use yazi_shared::event::CmdCow;
|
||||
|
||||
use super::cd::CdSource;
|
||||
use crate::tab::Tab;
|
||||
|
||||
impl Tab {
|
||||
pub fn back(&mut self, _: CmdCow) {
|
||||
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));
|
||||
self.cd((u, CdSource::Back));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ use crate::tab::Tab;
|
|||
|
||||
struct Opt {
|
||||
target: Url,
|
||||
source: OptSource,
|
||||
source: CdSource,
|
||||
interactive: bool,
|
||||
}
|
||||
|
||||
impl From<CmdCow> for Opt {
|
||||
fn from(mut c: CmdCow) -> Self {
|
||||
Self {
|
||||
source: OptSource::Cd,
|
||||
source: CdSource::Cd,
|
||||
interactive: c.bool("interactive"),
|
||||
..Self::from(c.take_first_url().unwrap_or_default())
|
||||
}
|
||||
|
|
@ -28,11 +28,11 @@ impl From<CmdCow> for Opt {
|
|||
}
|
||||
|
||||
impl From<Url> for Opt {
|
||||
fn from(target: Url) -> Self { Self::from((target, OptSource::Cd)) }
|
||||
fn from(target: Url) -> Self { Self::from((target, CdSource::Cd)) }
|
||||
}
|
||||
|
||||
impl From<(Url, OptSource)> for Opt {
|
||||
fn from((mut target, source): (Url, OptSource)) -> Self {
|
||||
impl From<(Url, CdSource)> for Opt {
|
||||
fn from((mut target, source): (Url, CdSource)) -> Self {
|
||||
if target.is_regular() {
|
||||
target = Url::from(expand_path(&target));
|
||||
}
|
||||
|
|
@ -60,6 +60,16 @@ impl Tab {
|
|||
self.history.insert(rep.url.to_owned(), rep);
|
||||
}
|
||||
|
||||
// Backstack
|
||||
if opt.source.big_jump() {
|
||||
if self.current.url.is_regular() {
|
||||
self.backstack.push(&self.current.url);
|
||||
}
|
||||
if opt.target.is_regular() {
|
||||
self.backstack.push(&opt.target);
|
||||
}
|
||||
}
|
||||
|
||||
// Current
|
||||
let rep = self.history.remove_or(&opt.target);
|
||||
let rep = mem::replace(&mut self.current, rep);
|
||||
|
|
@ -72,11 +82,6 @@ impl Tab {
|
|||
self.parent = Some(self.history.remove_or(&parent));
|
||||
}
|
||||
|
||||
// Backstack
|
||||
if opt.source.big_jump() && opt.target.is_regular() {
|
||||
self.backstack.push(&opt.target);
|
||||
}
|
||||
|
||||
Pubsub::pub_from_cd(self.id, self.cwd());
|
||||
self.hover(None);
|
||||
|
||||
|
|
@ -118,7 +123,8 @@ impl Tab {
|
|||
|
||||
// --- OptSource
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub(super) enum OptSource {
|
||||
pub enum CdSource {
|
||||
Tab,
|
||||
Cd,
|
||||
Reveal,
|
||||
Enter,
|
||||
|
|
@ -127,7 +133,7 @@ pub(super) enum OptSource {
|
|||
Back,
|
||||
}
|
||||
|
||||
impl OptSource {
|
||||
impl CdSource {
|
||||
#[inline]
|
||||
fn big_jump(self) -> bool { self == Self::Cd || self == Self::Reveal }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use yazi_shared::event::CmdCow;
|
||||
|
||||
use super::cd::CdSource;
|
||||
use crate::tab::Tab;
|
||||
|
||||
impl Tab {
|
||||
|
|
@ -8,6 +9,6 @@ impl Tab {
|
|||
.hovered()
|
||||
.filter(|h| h.is_dir())
|
||||
.map(|h| h.url.to_regular())
|
||||
.map(|u| self.cd((u, super::cd::OptSource::Enter)));
|
||||
.map(|u| self.cd((u, CdSource::Enter)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
use yazi_shared::event::CmdCow;
|
||||
|
||||
use super::cd::CdSource;
|
||||
use crate::tab::Tab;
|
||||
|
||||
impl Tab {
|
||||
pub fn forward(&mut self, _: CmdCow) {
|
||||
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));
|
||||
self.cd((u, CdSource::Forward));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use yazi_shared::event::CmdCow;
|
||||
|
||||
use super::cd::CdSource;
|
||||
use crate::tab::Tab;
|
||||
|
||||
struct Opt;
|
||||
|
|
@ -19,6 +20,6 @@ impl Tab {
|
|||
.and_then(|h| h.url.parent_url())
|
||||
.filter(|u| u != self.cwd())
|
||||
.or_else(|| self.cwd().parent_url())
|
||||
.map(|u| self.cd((u.into_regular(), super::cd::OptSource::Leave)));
|
||||
.map(|u| self.cd((u.into_regular(), CdSource::Leave)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ use yazi_fs::{File, FilesOp, expand_path};
|
|||
use yazi_proxy::MgrProxy;
|
||||
use yazi_shared::{event::CmdCow, url::Url};
|
||||
|
||||
use super::cd::CdSource;
|
||||
use crate::tab::Tab;
|
||||
|
||||
struct Opt {
|
||||
target: Url,
|
||||
source: CdSource,
|
||||
no_dummy: bool,
|
||||
}
|
||||
|
||||
|
|
@ -16,11 +18,16 @@ impl From<CmdCow> for Opt {
|
|||
target = Url::from(expand_path(&target));
|
||||
}
|
||||
|
||||
Self { target, no_dummy: c.bool("no-dummy") }
|
||||
Self { target, source: CdSource::Reveal, no_dummy: c.bool("no-dummy") }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Url> for Opt {
|
||||
fn from(target: Url) -> Self { Self { target, no_dummy: false } }
|
||||
fn from(target: Url) -> Self { Self { target, source: CdSource::Reveal, no_dummy: false } }
|
||||
}
|
||||
|
||||
impl From<(Url, CdSource)> for Opt {
|
||||
fn from((target, source): (Url, CdSource)) -> Self { Self { target, source, no_dummy: false } }
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
|
|
@ -30,7 +37,7 @@ impl Tab {
|
|||
return;
|
||||
};
|
||||
|
||||
self.cd((parent.clone(), super::cd::OptSource::Reveal));
|
||||
self.cd((parent.clone(), opt.source));
|
||||
self.current.hover(child.as_urn());
|
||||
|
||||
if !opt.no_dummy && self.hovered().is_none_or(|f| &child != f.urn()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue