diff --git a/yazi-core/src/tab/tab.rs b/yazi-core/src/tab/tab.rs index 99f5558c..a7c25901 100644 --- a/yazi-core/src/tab/tab.rs +++ b/yazi-core/src/tab/tab.rs @@ -1,5 +1,3 @@ -use std::iter; - use anyhow::Result; use ratatui::layout::Rect; use tokio::task::JoinHandle; @@ -96,7 +94,9 @@ impl Tab { } pub fn hovered_and_selected(&self) -> Box + '_> { - let Some(h) = self.hovered() else { return Box::new(iter::empty()) }; + let Some(h) = self.hovered() else { + return Box::new([UrlBuf::new()].into_iter().chain(self.selected.values())); + }; if self.selected.is_empty() { Box::new([&h.url, &h.url].into_iter()) } else { diff --git a/yazi-shared/src/loc/buf.rs b/yazi-shared/src/loc/buf.rs index b4936923..6b83160c 100644 --- a/yazi-shared/src/loc/buf.rs +++ b/yazi-shared/src/loc/buf.rs @@ -84,6 +84,10 @@ impl LocBuf { Ok(Self { inner: loc.inner, uri, urn }) } + // FIXME: use `LocBuf::empty()` when Rust 1.91.0 released + // pub const fn empty() -> Self { Self { inner: PathBuf::new(), uri: 0, urn: 0 } + // } + pub fn zeroed(path: impl Into) -> Self { let loc = Self::from(path.into()); let Loc { inner, uri, urn } = Loc::zeroed(&loc.inner); diff --git a/yazi-shared/src/url/buf.rs b/yazi-shared/src/url/buf.rs index 8d3b5224..bf78a70f 100644 --- a/yazi-shared/src/url/buf.rs +++ b/yazi-shared/src/url/buf.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, ffi::OsStr, fmt::{Debug, Formatter}, hash::BuildHasher, path::{Path, PathBuf}, str::FromStr}; +use std::{borrow::Cow, ffi::OsStr, fmt::{Debug, Formatter}, hash::BuildHasher, path::{Path, PathBuf}, str::FromStr, sync::OnceLock}; use anyhow::Result; use serde::{Deserialize, Serialize}; @@ -79,6 +79,16 @@ impl PartialEq> for &UrlBuf { } impl UrlBuf { + #[inline] + pub fn new() -> &'static Self { + static U: OnceLock = OnceLock::new(); + U.get_or_init(Self::default) + + // FIXME: use `LocBuf::empty()` when Rust 1.91.0 released + // static U: UrlBuf = UrlBuf { loc: LocBuf::empty(), scheme: Scheme::Regular + // }; &U + } + #[inline] pub fn join(&self, path: impl AsRef) -> Self { self.as_url().join(path) }