mirror of https://github.com/helix-editor/helix
feat: Collapse all yank-join commands into a single `:yank-join` with flags
parent
3ceae88c3a
commit
90a21cc4ba
|
@ -32,11 +32,9 @@
|
||||||
| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
|
| `:cquit`, `:cq` | Quit with exit code (default 1). Accepts an optional integer exit code (:cq 2). |
|
||||||
| `:cquit!`, `:cq!` | Force quit with exit code (default 1) ignoring unsaved changes. Accepts an optional integer exit code (:cq! 2). |
|
| `:cquit!`, `:cq!` | Force quit with exit code (default 1) ignoring unsaved changes. Accepts an optional integer exit code (:cq! 2). |
|
||||||
| `:theme` | Change the editor theme (show current theme if no name specified). |
|
| `:theme` | Change the editor theme (show current theme if no name specified). |
|
||||||
| `:yank-join` | Yank joined selections. A separator can be provided as first argument. Default value is newline. |
|
| `:yank-join`, `:yj` | Yank the selections joined with a separator |
|
||||||
| `:clipboard-yank` | Yank main selection into system clipboard. |
|
| `:clipboard-yank` | Yank main selection into system clipboard. |
|
||||||
| `:clipboard-yank-join` | Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline. |
|
|
||||||
| `:primary-clipboard-yank` | Yank main selection into system primary clipboard. |
|
| `:primary-clipboard-yank` | Yank main selection into system primary clipboard. |
|
||||||
| `:primary-clipboard-yank-join` | Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline. |
|
|
||||||
| `:clipboard-paste-after` | Paste system clipboard after selections. |
|
| `:clipboard-paste-after` | Paste system clipboard after selections. |
|
||||||
| `:clipboard-paste-before` | Paste system clipboard before selections. |
|
| `:clipboard-paste-before` | Paste system clipboard before selections. |
|
||||||
| `:clipboard-paste-replace` | Replace selections with content of system clipboard. |
|
| `:clipboard-paste-replace` | Replace selections with content of system clipboard. |
|
||||||
|
|
|
@ -975,29 +975,23 @@ fn yank_joined(cx: &mut compositor::Context, args: Args, event: PromptEvent) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
let doc = doc!(cx.editor);
|
let doc = doc!(cx.editor);
|
||||||
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
|
|
||||||
let separator = args.first().unwrap_or(&default_sep);
|
let separator = args
|
||||||
let register = cx
|
.get_flag("separator")
|
||||||
.editor
|
.unwrap_or_else(|| doc.line_ending.as_str());
|
||||||
.selected_register
|
|
||||||
.unwrap_or(cx.editor.config().default_yank_register);
|
let register = args
|
||||||
|
.get_flag("register")
|
||||||
|
.map(|reg| {
|
||||||
|
reg.parse::<char>()
|
||||||
|
.map_err(|_| anyhow!("Invalid register: {reg}"))
|
||||||
|
})
|
||||||
|
.transpose()?
|
||||||
|
.or(cx.editor.selected_register)
|
||||||
|
.unwrap_or_else(|| cx.editor.config().default_yank_register);
|
||||||
|
|
||||||
yank_joined_impl(cx.editor, separator, register);
|
yank_joined_impl(cx.editor, separator, register);
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn yank_joined_to_clipboard(
|
|
||||||
cx: &mut compositor::Context,
|
|
||||||
args: Args,
|
|
||||||
event: PromptEvent,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
if event != PromptEvent::Validate {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let doc = doc!(cx.editor);
|
|
||||||
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
|
|
||||||
let separator = args.first().unwrap_or(&default_sep);
|
|
||||||
yank_joined_impl(cx.editor, separator, '+');
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1014,22 +1008,6 @@ fn yank_main_selection_to_primary_clipboard(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn yank_joined_to_primary_clipboard(
|
|
||||||
cx: &mut compositor::Context,
|
|
||||||
args: Args,
|
|
||||||
event: PromptEvent,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
if event != PromptEvent::Validate {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let doc = doc!(cx.editor);
|
|
||||||
let default_sep = Cow::Borrowed(doc.line_ending.as_str());
|
|
||||||
let separator = args.first().unwrap_or(&default_sep);
|
|
||||||
yank_joined_impl(cx.editor, separator, '*');
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn paste_clipboard_after(
|
fn paste_clipboard_after(
|
||||||
cx: &mut compositor::Context,
|
cx: &mut compositor::Context,
|
||||||
_args: Args,
|
_args: Args,
|
||||||
|
@ -2939,12 +2917,26 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
},
|
},
|
||||||
TypableCommand {
|
TypableCommand {
|
||||||
name: "yank-join",
|
name: "yank-join",
|
||||||
aliases: &[],
|
aliases: &["yj"],
|
||||||
doc: "Yank joined selections. A separator can be provided as first argument. Default value is newline.",
|
doc: "Yank the selections joined with a separator",
|
||||||
fun: yank_joined,
|
fun: yank_joined,
|
||||||
completer: CommandCompleter::none(),
|
completer: CommandCompleter::none(),
|
||||||
signature: Signature {
|
signature: Signature {
|
||||||
positionals: (0, Some(1)),
|
positionals: (0, Some(0)),
|
||||||
|
flags: &[
|
||||||
|
Flag {
|
||||||
|
name: "separator",
|
||||||
|
alias: Some('s'),
|
||||||
|
doc: "Separator to between joined selections [default: newline]",
|
||||||
|
completions: Some(&[])
|
||||||
|
},
|
||||||
|
Flag {
|
||||||
|
name: "register",
|
||||||
|
alias: Some('r'),
|
||||||
|
doc: "Yank into this register",
|
||||||
|
completions: Some(&[])
|
||||||
|
}
|
||||||
|
],
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -2959,17 +2951,6 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TypableCommand {
|
|
||||||
name: "clipboard-yank-join",
|
|
||||||
aliases: &[],
|
|
||||||
doc: "Yank joined selections into system clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
|
|
||||||
fun: yank_joined_to_clipboard,
|
|
||||||
completer: CommandCompleter::none(),
|
|
||||||
signature: Signature {
|
|
||||||
positionals: (0, Some(1)),
|
|
||||||
..Signature::DEFAULT
|
|
||||||
},
|
|
||||||
},
|
|
||||||
TypableCommand {
|
TypableCommand {
|
||||||
name: "primary-clipboard-yank",
|
name: "primary-clipboard-yank",
|
||||||
aliases: &[],
|
aliases: &[],
|
||||||
|
@ -2981,17 +2962,6 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
|
||||||
..Signature::DEFAULT
|
..Signature::DEFAULT
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TypableCommand {
|
|
||||||
name: "primary-clipboard-yank-join",
|
|
||||||
aliases: &[],
|
|
||||||
doc: "Yank joined selections into system primary clipboard. A separator can be provided as first argument. Default value is newline.", // FIXME: current UI can't display long doc.
|
|
||||||
fun: yank_joined_to_primary_clipboard,
|
|
||||||
completer: CommandCompleter::none(),
|
|
||||||
signature: Signature {
|
|
||||||
positionals: (0, Some(1)),
|
|
||||||
..Signature::DEFAULT
|
|
||||||
},
|
|
||||||
},
|
|
||||||
TypableCommand {
|
TypableCommand {
|
||||||
name: "clipboard-paste-after",
|
name: "clipboard-paste-after",
|
||||||
aliases: &[],
|
aliases: &[],
|
||||||
|
|
|
@ -5,6 +5,7 @@ use super::*;
|
||||||
mod insert;
|
mod insert;
|
||||||
mod movement;
|
mod movement;
|
||||||
mod write;
|
mod write;
|
||||||
|
mod yank_join;
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn search_selection_detect_word_boundaries_at_eof() -> anyhow::Result<()> {
|
async fn search_selection_detect_word_boundaries_at_eof() -> anyhow::Result<()> {
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn no_flags() -> anyhow::Result<()> {
|
||||||
|
test((
|
||||||
|
indoc! {"\
|
||||||
|
#[o|]#ne
|
||||||
|
#(t|)#wo
|
||||||
|
three"
|
||||||
|
},
|
||||||
|
":yank-join<ret>p",
|
||||||
|
indoc! {"\
|
||||||
|
o#[o
|
||||||
|
t|]#ne
|
||||||
|
t#(o
|
||||||
|
t|)#wo
|
||||||
|
three"
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn separator_flag() -> anyhow::Result<()> {
|
||||||
|
test((
|
||||||
|
indoc! {"\
|
||||||
|
#[o|]#ne
|
||||||
|
#(t|)#wo
|
||||||
|
three"
|
||||||
|
},
|
||||||
|
":yank-join --separator x<ret>p",
|
||||||
|
indoc! {"\
|
||||||
|
o#[oxt|]#ne
|
||||||
|
t#(oxt|)#wo
|
||||||
|
three"
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn register_flag() -> anyhow::Result<()> {
|
||||||
|
test((
|
||||||
|
indoc! {"\
|
||||||
|
#[o|]#ne
|
||||||
|
#(t|)#wo
|
||||||
|
three"
|
||||||
|
},
|
||||||
|
// 1. Yank the two selections into register `x`
|
||||||
|
// 2. Move cursor down + right
|
||||||
|
// 3. Yank two other selections into the default register
|
||||||
|
// 4. Move cursor back up + left, to the original position
|
||||||
|
// 5. Pasting from register `x` will paste as if actions 2, 3 and 4 never occured
|
||||||
|
":yank-join --register x<ret>jl:yank-join<ret>kh\"xp",
|
||||||
|
indoc! {"\
|
||||||
|
o#[o
|
||||||
|
t|]#ne
|
||||||
|
t#(o
|
||||||
|
t|)#wo
|
||||||
|
three"
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue