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.
This commit is contained in:
Rolo 2024-06-22 01:35:44 -07:00
parent 6fbc85e168
commit b58fe565d4

View File

@ -4144,18 +4144,19 @@ fn yank_joined_impl(editor: &mut Editor, separator: &str, register: char) {
let selection = doc.selection(view.id);
let selections = selection.len();
let separator = helix_stdx::str::unescape(separator);
let joined = selection
.fragments(text)
.fold(String::new(), |mut acc, fragment| {
if !acc.is_empty() {
acc.push_str(separator);
acc.push_str(&separator);
}
acc.push_str(&fragment);
acc
});
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}",
if selections == 1 { "" } else { "s" }
)),