Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reuse the code previewer seeking behavior for json, archive, and empty #1721

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions yazi-core/src/manager/commands/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ impl Manager {

let ext = url.extension();
match by {
"stem" => ext.map_or_else(String::new, |s| format!(".{}", s.to_string_lossy().into_owned())),
"stem" => ext.map_or_else(String::new, |s| format!(".{}", s.to_string_lossy())),
"ext" if ext.is_some() => format!("{}.", url.file_stem().unwrap().to_string_lossy()),
"dot_ext" if ext.is_some() => url.file_stem().unwrap().to_string_lossy().into_owned(),
_ => url.file_name().map_or_else(String::new, |s| s.to_string_lossy().into_owned()),
_ => url.name().to_string_lossy().into_owned(),
}
}
}
2 changes: 1 addition & 1 deletion yazi-core/src/tab/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Tab {
s.push(match opt.type_.as_str() {
"path" => u.as_os_str(),
"dirname" => u.parent().map_or(OsStr::new(""), |p| p.as_os_str()),
"filename" => u.file_name().unwrap_or(OsStr::new("")),
"filename" => u.name(),
"name_without_ext" => u.file_stem().unwrap_or(OsStr::new("")),
_ => return,
});
Expand Down
11 changes: 1 addition & 10 deletions yazi-plugin/preset/plugins/archive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,7 @@ function M:peek()
end
end

function M:seek(units)
local h = cx.active.current.hovered
if h and h.url == self.file.url then
local step = math.floor(units * self.area.h / 10)
ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
})
end
end
function M:seek(units) require("code").seek(self, units) end

function M.spawn_7z(args)
local last_error = nil
Expand Down
11 changes: 1 addition & 10 deletions yazi-plugin/preset/plugins/empty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ function M:peek()
end
end

function M:seek(units)
local h = cx.active.current.hovered
if h and h.url == self.file.url then
local step = math.floor(units * self.area.h / 10)
ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
})
end
end
function M:seek(units) require("code").seek(self, units) end

return M
11 changes: 1 addition & 10 deletions yazi-plugin/preset/plugins/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ function M:peek()
end
end

function M:seek(units)
local h = cx.active.current.hovered
if h and h.url == self.file.url then
local step = math.floor(units * self.area.h / 10)
ya.manager_emit("peek", {
math.max(0, cx.active.preview.skip + step),
only_if = self.file.url,
})
end
end
function M:seek(units) require("code").seek(self, units) end

return M
17 changes: 7 additions & 10 deletions yazi-scheduler/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ impl Scheduler {
}

pub fn file_copy(&self, from: Url, mut to: Url, force: bool, follow: bool) {
let name = format!("Copy {:?} to {:?}", from, to);
let id = self.ongoing.lock().add(TaskKind::User, name);
let id = self.ongoing.lock().add(TaskKind::User, format!("Copy {from} to {to}"));

if to.starts_with(&from) && to != from {
self.new_and_fail(id, "Cannot copy directory into itself").ok();
Expand All @@ -122,8 +121,7 @@ impl Scheduler {
}

pub fn file_link(&self, from: Url, mut to: Url, relative: bool, force: bool) {
let name = format!("Link {from:?} to {to:?}");
let id = self.ongoing.lock().add(TaskKind::User, name);
let id = self.ongoing.lock().add(TaskKind::User, format!("Link {from} to {to}"));

let file = self.file.clone();
self.send_micro(id, LOW, async move {
Expand All @@ -137,8 +135,7 @@ impl Scheduler {
}

pub fn file_hardlink(&self, from: Url, mut to: Url, force: bool, follow: bool) {
let name = format!("Hardlink {:?} to {:?}", from, to);
let id = self.ongoing.lock().add(TaskKind::User, name);
let id = self.ongoing.lock().add(TaskKind::User, format!("Hardlink {from} to {to}"));

if to.starts_with(&from) && to != from {
self.new_and_fail(id, "Cannot hardlink directory into itself").ok();
Expand All @@ -156,7 +153,7 @@ impl Scheduler {

pub fn file_delete(&self, target: Url) {
let mut ongoing = self.ongoing.lock();
let id = ongoing.add(TaskKind::User, format!("Delete {:?}", target));
let id = ongoing.add(TaskKind::User, format!("Delete {target}"));

ongoing.hooks.insert(id, {
let target = target.clone();
Expand Down Expand Up @@ -185,7 +182,7 @@ impl Scheduler {

pub fn file_trash(&self, target: Url) {
let mut ongoing = self.ongoing.lock();
let id = ongoing.add(TaskKind::User, format!("Trash {:?}", target));
let id = ongoing.add(TaskKind::User, format!("Trash {target}"));

ongoing.hooks.insert(id, {
let target = target.clone();
Expand Down Expand Up @@ -258,7 +255,7 @@ impl Scheduler {
let mut ongoing = self.ongoing.lock();

for target in targets {
let id = ongoing.add(TaskKind::Preload, format!("Calculate the size of {:?}", target));
let id = ongoing.add(TaskKind::Preload, format!("Calculate the size of {target}"));
let target = target.clone();
let throttle = throttle.clone();

Expand Down Expand Up @@ -435,7 +432,7 @@ impl Scheduler {
async move {
if let Err(e) = f.await {
prog.send(TaskProg::New(id, 0)).ok();
prog.send(TaskProg::Fail(id, format!("Task initialization failed:\n{e}"))).ok();
prog.send(TaskProg::Fail(id, format!("Task initialization failed:\n{e:?}"))).ok();
}
}
.boxed(),
Expand Down