Skip to content

Commit

Permalink
feat: add a new tab parameter for all tab-specific commands to spec…
Browse files Browse the repository at this point in the history
…ify which one (#1885)
  • Loading branch information
sxyazi authored Nov 3, 2024
1 parent 6086134 commit 362fbeb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions yazi-core/src/manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ impl Manager {
pub fn current_mut(&mut self) -> &mut Folder { &mut self.active_mut().current }

#[inline]
pub fn current_or(&self, idx: Option<Id>) -> &Folder { &self.active_or(idx).current }
pub fn current_or(&self, id: Option<Id>) -> &Folder { &self.active_or(id).current }

#[inline]
pub fn current_or_mut(&mut self, idx: Option<Id>) -> &mut Folder {
&mut self.active_or_mut(idx).current
pub fn current_or_mut(&mut self, id: Option<Id>) -> &mut Folder {
&mut self.active_or_mut(id).current
}

#[inline]
Expand Down
3 changes: 3 additions & 0 deletions yazi-core/src/manager/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ impl Tabs {
self.active_mut()
}
}

#[inline]
pub fn find_mut(&mut self, id: Id) -> Option<&mut Tab> { self.iter_mut().find(|t| t.id == id) }
}

impl Deref for Tabs {
Expand Down
8 changes: 7 additions & 1 deletion yazi-fm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ impl<'a> Executor<'a> {
};
(ACTIVE, $name:ident $(,$args:expr)*) => {
if cmd.name == stringify!($name) {
return self.app.cx.manager.active_mut().$name(cmd, $($args),*);
return if let Some(tab) = cmd.get("tab") {
let Some(id) = tab.as_id() else { return };
let Some(tab) = self.app.cx.manager.tabs.find_mut(id) else { return };
tab.$name(cmd, $($args),*)
} else {
self.app.cx.manager.active_mut().$name(cmd, $($args),*)
};
}
};
(TABS, $name:ident) => {
Expand Down

0 comments on commit 362fbeb

Please sign in to comment.