helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
31.15k stars 2.3k forks source link

feat(commands): unescape yank-join separator #11012

Open RoloEdits opened 1 week ago

RoloEdits commented 1 week ago

Introduces a str module and an unescape function to helix-stdx, which processes escape sequences in strings and converts them into their corresponding literal characters. The function handles a variety of escape sequences, including:

The function does not unescape sequences like \\ to \, leaving them as they are. This opinionated behavior ensures that only certain escape sequences are processed, and is built around user input, not general input.

Given that its based around user input, a conservative approach was taken for handling bad input, where if the string cannot be processed as expected, it returns the original input.

Examples:

The implementation also includes tests, but no guarantees for edge cases.

Previously, the yank-join command joined the current selection with the separator as-is. With this update, escape sequences in the separator are unescaped to their corresponding literal characters before joining the selection, aligning with user expectations:

Newline: separator_unescape_newline

Tab: separator_unescape_tab

Unicode: separator_unescape_unicode

Closes: #10993

RoloEdits commented 1 week ago

In testing the user input I noticed that ' and " input by themselves, :yank-join ", would result in newlines. This exists on master as well, and seems to stem from how Shellwords::from handles these inputs, which results in the TypedCommand args being empty, and defaulting to the line_ending as a result. I thought about trying to tackle that here, but the scope would be beyond the current PR, so going to open this for review.