diff --git a/yazi-widgets/src/input/commands/complete.rs b/yazi-widgets/src/input/commands/complete.rs index d2986542..6b2ebf45 100644 --- a/yazi-widgets/src/input/commands/complete.rs +++ b/yazi-widgets/src/input/commands/complete.rs @@ -15,6 +15,17 @@ const SEPARATOR: char = std::path::MAIN_SEPARATOR; impl Input { pub fn complete(&mut self, opt: CompleteOpt) -> Result { let (before, after) = self.partition(); + + // Strip the remainder of the current path component from `after`, so that + // completing when the cursor is in the middle of a word replaces the entire + // word instead of appending the completion before the leftover suffix. + // e.g. input "/home/user/D|oc" (cursor at |) completing "Documents/" should + // yield "/home/user/Documents/", not "/home/user/Documents/oc". + let after = match after.find(SEPARATOR) { + Some(i) => &after[i..], + None => "", + }; + let new = if let Some((prefix, _)) = before.rsplit_once(SEPARATOR) { format!("{prefix}/{}{after}", opt.completable()).replace(SEPARATOR, MAIN_SEPARATOR_STR) } else {