Make ticket optional for cmp:trigger

This commit is contained in:
Simon Börjesson 2025-07-09 01:33:07 +02:00
parent 452b435b71
commit 2fd94ab4c7
2 changed files with 12 additions and 6 deletions

View file

@ -12,18 +12,24 @@ use crate::cmp::Cmp;
impl Cmp {
#[yazi_codegen::command]
pub fn trigger(&mut self, opt: TriggerOpt) {
if opt.ticket < self.ticket {
if let Some(ticket) = opt.ticket {
if ticket < self.ticket {
return;
} else {
self.ticket = ticket;
}
}
self.ticket = opt.ticket;
let Some((parent, word)) = Self::split_path(&opt.word) else {
return self.close(false);
};
if self.caches.contains_key(&parent) {
return self.show(
Cmd::default().with_any("cache-name", parent).with("word", word).with("ticket", opt.ticket),
Cmd::default()
.with_any("cache-name", parent)
.with("word", word)
.with("ticket", self.ticket),
);
}

View file

@ -2,14 +2,14 @@ use yazi_shared::{Id, SStr, event::{CmdCow, Data}};
pub struct TriggerOpt {
pub word: SStr,
pub ticket: Id,
pub ticket: Option<Id>,
}
impl From<CmdCow> for TriggerOpt {
fn from(mut c: CmdCow) -> Self {
Self {
word: c.take_first_str().unwrap_or_default(),
ticket: c.get("ticket").and_then(Data::as_id).unwrap_or_default(),
ticket: c.get("ticket").and_then(Data::as_id),
}
}
}