mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: support opening and previewing files inside of Directories with invalid UTF-8 name
.. ..
This commit is contained in:
parent
a0ce7c0ae7
commit
e8908e8612
4 changed files with 32 additions and 8 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue