Skip to content

Commit

Permalink
feat: echopy command
Browse files Browse the repository at this point in the history
  • Loading branch information
Axlefublr committed Nov 4, 2024
1 parent 2c2fe23 commit 2c9bda6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ It will look wonky if you do, so it makes the most sense to make a hotkey to tog

`:echo` command lets you print a message to the messages line. Useful for when you want to give visual feedback to some mappings, or to use [command expansions](#command-expansions).

`:echopy` command is exactly like `:echo`, but *also* puts the result into your clipboard. For example, you can do `:echopy %p` to copy the full path to the current file to your clipboard (this is elaborated on [later](#command-expansions)).

All pickers now take up the entire screen, rather than 90%. Thanks to @satoqz for figuring out how to do this! :D

The `insert-final-newline` option now only inserts newline if the file is not empty.
Expand Down
1 change: 1 addition & 0 deletions book/src/generated/typable-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@
| `:read`, `:r` | Load a file into buffer |
| `:random`, `:rng`, `:rnd` | Randomize your selections |
| `:echo`, `:c` | Print to the messages line |
| `:echopy`, `:cc` | Put string into selected register (`+` by default) |
| `:reload-history` | Reload history files for persistent state |
5 changes: 1 addition & 4 deletions helix-core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ mod test {
#[test]
fn print_multi_code_point_grapheme() {
assert_eq!(
(
String::from("hello 👨‍👩‍👧‍👦 goodbye"),
Selection::single(13, 6)
),
(String::from("hello 👨‍👩‍👧‍👦 goodbye"), Selection::single(13, 6)),
print("hello #[|👨‍👩‍👧‍👦]# goodbye")
);
}
Expand Down
7 changes: 7 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: echo,
signature: CommandSignature::none(),
},
TypableCommand {
name: "echopy",
aliases: &["cc"],
doc: "Put string into clipboard",
fun: echopy,
signature: CommandSignature::none(),
},
TypableCommand {
name: "reload-history",
aliases: &[],
Expand Down
18 changes: 18 additions & 0 deletions helix-term/src/commands/typed/forktyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,21 @@ pub fn echo(
cx.editor.set_status(args.join(" "));
Ok(())
}

pub fn echopy(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}

let expansion = args.join(" ");
match cx.editor.registers.write('+', vec![expansion.clone()]) {
Ok(_) => cx.editor.set_status(expansion),
Err(err) => cx.editor.set_error(err.to_string()),
}

Ok(())
}

0 comments on commit 2c9bda6

Please sign in to comment.