mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add --hovered to the copy command
Similar to the `open`, `rename` and `remove` commands, the `--hovered` flag will cause the copy command to operate only on the hovered file.
This commit is contained in:
parent
01a13fd664
commit
084f0083da
1 changed files with 5 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{borrow::Cow, ffi::{OsStr, OsString}, path::Path};
|
use std::{borrow::Cow, ffi::{OsStr, OsString}, path::Path, iter::once};
|
||||||
|
|
||||||
use yazi_plugin::CLIPBOARD;
|
use yazi_plugin::CLIPBOARD;
|
||||||
use yazi_shared::event::CmdCow;
|
use yazi_shared::event::CmdCow;
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::tab::Tab;
|
||||||
struct Opt {
|
struct Opt {
|
||||||
type_: Cow<'static, str>,
|
type_: Cow<'static, str>,
|
||||||
separator: Separator,
|
separator: Separator,
|
||||||
|
hovered: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CmdCow> for Opt {
|
impl From<CmdCow> for Opt {
|
||||||
|
|
@ -15,6 +16,7 @@ impl From<CmdCow> for Opt {
|
||||||
Self {
|
Self {
|
||||||
type_: c.take_first_str().unwrap_or_default(),
|
type_: c.take_first_str().unwrap_or_default(),
|
||||||
separator: c.str("separator").unwrap_or_default().into(),
|
separator: c.str("separator").unwrap_or_default().into(),
|
||||||
|
hovered: c.bool("hovered"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +29,8 @@ impl Tab {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = OsString::new();
|
let mut s = OsString::new();
|
||||||
let mut it = self.selected_or_hovered().peekable();
|
let Some(hovered) = self.hovered() else { if opt.hovered { return } };
|
||||||
|
let mut it = (if opt.hovered { once(hovered) } else { self.selected_or_hovered() }).peekable();
|
||||||
while let Some(u) = it.next() {
|
while let Some(u) = it.next() {
|
||||||
s.push(match opt.type_.as_ref() {
|
s.push(match opt.type_.as_ref() {
|
||||||
"path" => opt.separator.transform(u),
|
"path" => opt.separator.transform(u),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue