mirror of
https://github.com/sxyazi/yazi.git
synced 2024-10-26 11:11:12 +03:00
feat: add --hovered
option to the rename
and remove
commands (#1227)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
626053da25
commit
9961251248
@ -113,7 +113,7 @@ previewers = [
|
||||
{ mime = "application/pdf", run = "pdf" },
|
||||
# Archive
|
||||
{ mime = "application/{,g}zip", run = "archive" },
|
||||
{ mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", run = "archive" },
|
||||
{ mime = "application/x-{tar,bzip*,7z-compressed,xz,rar,iso9660-image}", run = "archive" },
|
||||
# Font
|
||||
{ mime = "font/*", run = "font" },
|
||||
{ mime = "application/vnd.ms-opentype", run = "font" },
|
||||
|
@ -7,6 +7,7 @@ use crate::{manager::Manager, tasks::Tasks};
|
||||
pub struct Opt {
|
||||
force: bool,
|
||||
permanently: bool,
|
||||
hovered: bool,
|
||||
targets: Vec<Url>,
|
||||
}
|
||||
|
||||
@ -15,6 +16,7 @@ impl From<Cmd> for Opt {
|
||||
Self {
|
||||
force: c.bool("force"),
|
||||
permanently: c.bool("permanently"),
|
||||
hovered: c.bool("hovered"),
|
||||
targets: c.take_any("targets").unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
@ -25,9 +27,16 @@ impl Manager {
|
||||
if !self.active_mut().try_escape_visual() {
|
||||
return;
|
||||
}
|
||||
let Some(hovered) = self.hovered().map(|h| &h.url) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut opt = opt.into() as Opt;
|
||||
opt.targets = self.selected_or_hovered(false).cloned().collect();
|
||||
opt.targets = if opt.hovered {
|
||||
vec![hovered.clone()]
|
||||
} else {
|
||||
self.selected_or_hovered(false).cloned().collect()
|
||||
};
|
||||
|
||||
if opt.force {
|
||||
return self.remove_do(opt, tasks);
|
||||
|
@ -10,17 +10,19 @@ use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, paths_to_same_
|
||||
use crate::manager::Manager;
|
||||
|
||||
pub struct Opt {
|
||||
force: bool,
|
||||
empty: String,
|
||||
cursor: String,
|
||||
hovered: bool,
|
||||
force: bool,
|
||||
empty: String,
|
||||
cursor: String,
|
||||
}
|
||||
|
||||
impl From<Cmd> for Opt {
|
||||
fn from(mut c: Cmd) -> Self {
|
||||
Self {
|
||||
force: c.bool("force"),
|
||||
empty: c.take_str("empty").unwrap_or_default(),
|
||||
cursor: c.take_str("cursor").unwrap_or_default(),
|
||||
hovered: c.bool("hovered"),
|
||||
force: c.bool("force"),
|
||||
empty: c.take_str("empty").unwrap_or_default(),
|
||||
cursor: c.take_str("cursor").unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,15 +31,16 @@ impl Manager {
|
||||
pub fn rename(&mut self, opt: impl Into<Opt>) {
|
||||
if !self.active_mut().try_escape_visual() {
|
||||
return;
|
||||
} else if !self.active().selected.is_empty() {
|
||||
return self.bulk_rename();
|
||||
}
|
||||
|
||||
let Some(hovered) = self.hovered().map(|h| h.url()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let opt = opt.into() as Opt;
|
||||
if !opt.hovered && !self.active().selected.is_empty() {
|
||||
return self.bulk_rename();
|
||||
}
|
||||
|
||||
let name = Self::empty_url_part(&hovered, &opt.empty);
|
||||
let cursor = match opt.cursor.as_str() {
|
||||
"start" => Some(0),
|
||||
|
@ -45,7 +45,7 @@ function M:peek()
|
||||
if size > 0 then
|
||||
sizes[#sizes + 1] = ui.Line(string.format(" %s ", ya.readable_size(size)))
|
||||
else
|
||||
sizes[#sizes + 1] = ui.Line(" - ")
|
||||
sizes[#sizes + 1] = ui.Line("")
|
||||
end
|
||||
|
||||
::continue::
|
||||
|
Loading…
Reference in New Issue
Block a user