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