feat: add a new tab parameter for all tab-specific commands to specify which one (#1885)

This commit is contained in:
三咲雅 · Misaki Masa 2024-11-03 23:58:14 +08:00 committed by GitHub
parent 6086134d41
commit 362fbebcc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 4 deletions

View file

@ -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]

View file

@ -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 {

View file

@ -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) => {