helix icon indicating copy to clipboard operation
helix copied to clipboard

Split Bug at Start of Line

Open joegm opened this issue 3 years ago • 1 comments
trafficstars

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

joegm avatar Sep 15 '22 15:09 joegm

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

the-mikedavis avatar Sep 16 '22 10:09 the-mikedavis

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.

palango avatar Dec 13 '23 20:12 palango