Open RoloEdits opened 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.
Introduces a
str
module and anunescape
function tohelix-stdx
, which processes escape sequences in strings and converts them into their corresponding literal characters. The function handles a variety of escape sequences, including:\n
for newlines\t
for tabs\u{...}
for Unicode charactersThe 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:
unescape("hello\\nworld")
results in"hello\nworld"
.unescape("hello\\tworld")
results in"hello\tworld"
.unescape("hello\\u{1f929}world")
results in"hello🤩world"
.unescape("hello\\u{999999999}world")
results in the original"hello\\u{999999999}world"
.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](https://github.com/helix-editor/helix/assets/12489689/dcc917ee-6a08-4711-9062-d32c4cc2edd0)
Tab:![separator_unescape_tab](https://github.com/helix-editor/helix/assets/12489689/94f9a594-d2aa-4171-b0dd-e41f46a931a6)
Unicode:![separator_unescape_unicode](https://github.com/helix-editor/helix/assets/12489689/cdf251f7-6a56-4efa-a42b-5de3f8efc9a8)
Closes: #10993