feat(commands): unescape `yank-join` separator

This commit enhances the `yank-join` command by incorporating the
`unescape` function to process the separator provided by the user. This
improvement ensures that any escape sequences in the separator are correctly
interpreted, aligning with user expectations.

Previously, the `yank-join` command joined the current selection with the
separator as-is. With this update, escape sequences in the separator such as:
- `\\n` for newlines
- `\\t` for tabs
- `\\u{...}` for Unicode characters

are unescaped to their corresponding literal characters before joining the
selection.
pull/11012/head
Rolo 5 months ago
parent 6fbc85e168
commit b58fe565d4

@ -4144,18 +4144,19 @@ fn yank_joined_impl(editor: &mut Editor, separator: &str, register: char) {
let selection = doc.selection(view.id); let selection = doc.selection(view.id);
let selections = selection.len(); let selections = selection.len();
let separator = helix_stdx::str::unescape(separator);
let joined = selection let joined = selection
.fragments(text) .fragments(text)
.fold(String::new(), |mut acc, fragment| { .fold(String::new(), |mut acc, fragment| {
if !acc.is_empty() { if !acc.is_empty() {
acc.push_str(separator); acc.push_str(&separator);
} }
acc.push_str(&fragment); acc.push_str(&fragment);
acc acc
}); });
match editor.registers.write(register, vec![joined]) { match editor.registers.write(register, vec![joined]) {
Ok(_) => editor.set_status(format!( Ok(()) => editor.set_status(format!(
"joined and yanked {selections} selection{} to register {register}", "joined and yanked {selections} selection{} to register {register}",
if selections == 1 { "" } else { "s" } if selections == 1 { "" } else { "s" }
)), )),

Loading…
Cancel
Save