yazi_widgets/input/actor/
complete.rs1use std::path::MAIN_SEPARATOR_STR;
2
3use anyhow::Result;
4use yazi_macro::{act, render, succ};
5use yazi_shared::data::Data;
6
7use crate::input::{Input, SEPARATOR, parser::CompleteOpt};
8
9impl Input {
10 pub fn complete(&mut self, opt: CompleteOpt) -> Result<Data> {
11 let (before, after) = self.partition();
12 let new = if let Some((prefix, _)) = before.rsplit_once(SEPARATOR) {
13 format!("{prefix}/{}{after}", opt.completable()).replace(SEPARATOR, MAIN_SEPARATOR_STR)
14 } else {
15 format!("{}{after}", opt.completable()).replace(SEPARATOR, MAIN_SEPARATOR_STR)
16 };
17
18 let snap = self.snap_mut();
19 if new == snap.value {
20 succ!();
21 }
22
23 let delta = new.chars().count() as isize - snap.count() as isize;
24 snap.value = new;
25
26 act!(r#move, self, delta)?;
27 self.flush_type();
28 succ!(render!());
29 }
30}