feat: support opening and previewing files inside of Directories with invalid UTF-8 name

..

..
This commit is contained in:
TKperson 2025-06-18 02:24:51 -07:00
parent a0ce7c0ae7
commit e8908e8612
No known key found for this signature in database
GPG key ID: 8A4D0A490CD9919A
4 changed files with 32 additions and 8 deletions

View file

@ -7,14 +7,14 @@ use yazi_shared::{event::CmdCow, url::Url};
use crate::{mgr::{LINKED, Mgr}, tasks::Tasks};
pub struct Opt {
updates: HashMap<Cow<'static, str>, Cow<'static, str>>,
updates: HashMap<Url, Cow<'static, str>>,
}
impl TryFrom<CmdCow> for Opt {
type Error = ();
fn try_from(mut c: CmdCow) -> Result<Self, Self::Error> {
Ok(Self { updates: c.try_take("updates").ok_or(())?.into_dict_string() })
Ok(Self { updates: c.try_take("updates").ok_or(())?.into_dict() })
}
}
@ -28,7 +28,6 @@ impl Mgr {
let updates = opt
.updates
.into_iter()
.flat_map(|(url, mime)| Url::try_from(url.as_ref()).map(|u| (u, mime)))
.filter(|(url, mime)| self.mimetype.by_url(url) != Some(mime))
.fold(HashMap::new(), |mut map, (u, m)| {
for u in linked.from_file(&u) {

View file

@ -12,7 +12,7 @@ end
function M:fetch(job)
local urls = {}
for _, file in ipairs(job.files) do
urls[#urls + 1] = tostring(file.url)
urls[#urls + 1] = file.url
end
local cmd = os.getenv("YAZI_FILE_ONE") or "file"

View file

@ -146,8 +146,33 @@ impl UserData for Command {
me.inner.arg(String::from_utf8_lossy(&s.as_bytes()).as_ref());
}
Value::Table(t) => {
for s in t.sequence_values::<mlua::String>() {
me.inner.arg(String::from_utf8_lossy(&s?.as_bytes()).as_ref());
for v in t.sequence_values::<Value>() {
match &v? {
Value::String(s) => {
me.inner.arg(String::from_utf8_lossy(&s.as_bytes()).as_ref());
}
Value::UserData(ud) => {
if let Some(t) = ud.type_id() {
if t == TypeId::of::<yazi_binding::Url>() {
let url = ud.borrow::<yazi_binding::Url>()?;
me.inner.arg(url.as_os_str());
} else {
return Err(
"arg must be a string or Url, or table of strings or Urls.".into_lua_err(),
);
}
} else {
return Err(
"arg must be a string or Url, or table of strings or Urls.".into_lua_err(),
);
}
}
_ => {
return Err(
"arg must be a string or Url, or table of strings or Urls.".into_lua_err(),
);
}
}
}
}
_ => return Err("arg must be a string or table of strings".into_lua_err()),

View file

@ -63,14 +63,14 @@ impl Data {
}
}
pub fn into_dict_string(self) -> HashMap<Cow<'static, str>, Cow<'static, str>> {
pub fn into_dict(self) -> HashMap<Url, Cow<'static, str>> {
let Self::Dict(dict) = self else {
return Default::default();
};
let mut map = HashMap::with_capacity(dict.len());
for pair in dict {
if let (DataKey::String(k), Self::String(v)) = pair {
if let (DataKey::Url(k), Self::String(v)) = pair {
map.insert(k, v);
}
}