diff --git a/yazi-core/src/input/commands/backspace.rs b/yazi-core/src/input/commands/backspace.rs index c5fb688c..3796771f 100644 --- a/yazi-core/src/input/commands/backspace.rs +++ b/yazi-core/src/input/commands/backspace.rs @@ -15,9 +15,12 @@ impl From for Opt { impl Input { pub fn backspace(&mut self, opt: impl Into) { - let opt = opt.into() as Opt; let snap = self.snaps.current_mut(); + if snap.value.is_empty() { + return self.close(false); + } + let opt = opt.into() as Opt; if !opt.under && snap.cursor < 1 { return; } else if opt.under && snap.cursor >= snap.value.len() { diff --git a/yazi-core/src/input/commands/kill.rs b/yazi-core/src/input/commands/kill.rs index 3d0ae780..eeac2245 100644 --- a/yazi-core/src/input/commands/kill.rs +++ b/yazi-core/src/input/commands/kill.rs @@ -69,21 +69,21 @@ impl Input { let opt = opt.into() as Opt; let snap = self.snap_mut(); - match opt.kind.as_bytes() { - b"bol" => { + match opt.kind.as_str() { + "bol" => { let end = snap.idx(snap.cursor).unwrap_or(snap.len()); self.kill_range(..end) } - b"eol" => { + "eol" => { let start = snap.idx(snap.cursor).unwrap_or(snap.len()); self.kill_range(start..) } - b"backward" => { + "backward" => { let end = snap.idx(snap.cursor).unwrap_or(snap.len()); let start = end - Self::find_word_boundary(snap.value[..end].chars().rev()); self.kill_range(start..end) } - b"forward" => { + "forward" => { let start = snap.idx(snap.cursor).unwrap_or(snap.len()); let end = start + Self::find_word_boundary(snap.value[start..].chars()); self.kill_range(start..end) diff --git a/yazi-plugin/src/url/url.rs b/yazi-plugin/src/url/url.rs index 36755cae..e6301f22 100644 --- a/yazi-plugin/src/url/url.rs +++ b/yazi-plugin/src/url/url.rs @@ -9,7 +9,7 @@ pub struct Url; impl Url { pub fn register(lua: &Lua) -> mlua::Result<()> { lua.register_userdata_type::(|reg| { - reg.add_field_method_get("frag", |_, me| Ok(me.frag().map(ToOwned::to_owned))); + reg.add_field_method_get("frag", |lua, me| lua.create_string(me.frag())); reg.add_field_method_get("is_regular", |_, me| Ok(me.is_regular())); reg.add_field_method_get("is_search", |_, me| Ok(me.is_search())); reg.add_field_method_get("is_archive", |_, me| Ok(me.is_archive())); diff --git a/yazi-shared/src/fs/url.rs b/yazi-shared/src/fs/url.rs index d815e69e..cec810ff 100644 --- a/yazi-shared/src/fs/url.rs +++ b/yazi-shared/src/fs/url.rs @@ -8,7 +8,7 @@ const ENCODE_SET: &AsciiSet = &CONTROLS.add(b'#'); pub struct Url { scheme: UrlScheme, path: PathBuf, - frag: Option, + frag: String, } #[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -76,7 +76,7 @@ impl From<&str> for Url { } Some((a, b)) => { url.path = percent_decode_str(a).decode_utf8_lossy().into_owned().into(); - url.frag = Some(b.to_string()).filter(|s| !s.is_empty()); + url.frag = b.to_string(); } } url @@ -108,7 +108,8 @@ impl ToString for Url { }; let path = percent_encode(self.path.as_os_str().as_encoded_bytes(), ENCODE_SET); - let frag = self.frag.as_ref().map(|s| format!("#{s}")).unwrap_or_default(); + let frag = + Some(&self.frag).filter(|&s| !s.is_empty()).map(|s| format!("#{s}")).unwrap_or_default(); format!("{scheme}{path}{frag}") } } @@ -174,7 +175,7 @@ impl Url { #[inline] pub fn into_search(mut self, frag: String) -> Self { self.scheme = UrlScheme::Search; - self.frag = Some(frag); + self.frag = frag; self } @@ -196,7 +197,7 @@ impl Url { // --- Frag #[inline] - pub fn frag(&self) -> Option<&str> { self.frag.as_deref() } + pub fn frag(&self) -> &str { &self.frag } } impl From<&str> for UrlScheme {