helix-editor / helix

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

Split Bug at Start of Line #3850

Open n0s4 opened 2 years ago

n0s4 commented 2 years ago

Summary

When Split is used with a pattern that matches the start of a line, a selection is placed on the match even when there aren't any characters before it:

https://asciinema.org/a/NDCiZr7kfsMiUEuI88K37vybT

Reproduction Steps

I tried this: 1. `hx` 2. i| | | |(esc)S\\|(ret) I expected this to happen: The spaces in between and the newline would be selected Instead, this happened: There was an additional selection at the start of the line. ### Helix log N/A ### Platform Linux ### Terminal Emulator Alacritty ### Helix Version 22.08.1-61-gb191ecf8
the-mikedavis commented 2 years ago

This looks like https://github.com/helix-editor/helix/issues/3544. The same fix from https://github.com/helix-editor/helix/pull/3598/files can probably be applied to split_on_matches

palango commented 11 months ago

I think there are some edge cases that need to be decided. For example, on the input |a|b|c|, and a split on | what would be the expected outcome: three or four selections?

For me it feels more natural to have three, but have the special case of having the first selection remaining if there is no match. I implemented this in https://github.com/palango/helix/commit/17d1cd3d7be4677f635632d68af2c4612d6e4d31#diff-f218cebd639a867087e2a7abc84160d45888ad5bcff4ab10fcf7217cb16586e9R1303 , however the code isn't optimized yet.