helix icon indicating copy to clipboard operation
helix copied to clipboard

Fix multi byte auto pairs

Open dead10ck opened this issue 3 years ago • 6 comments

Currently if you configure any auto pairs with multi-byte Unicode characters, auto pairing does not produce a correct selection. This is because it is summing bytes, when it should be summing chars.

I took this opportunity to migrate the auto pairs tests to the integration tests, as this makes the tests much more readable with the new selection DSL, and will also allow testing more complicated intersections of auto pairs with other features like dedenting, as described in https://github.com/helix-editor/helix/pull/1379#issuecomment-1003724997. Ironically, the tests weren't passing, and it turns out the test selection DSL parser suffered from exactly the same bug, counting bytes and not chars. This was also fixed, and regression tests were added.

Fixes #3946.

dead10ck avatar Sep 29 '22 03:09 dead10ck

Sigh, Windows strikes again. Will look into the failure tomorrow.

dead10ck avatar Sep 29 '22 04:09 dead10ck

Ok, actually it turned out to be a legitimate preexisting bug!

The selection was not computed correctly in the case that the cursor was:

  1. a single grapheme in width
  2. this grapheme was more than one char
  3. the direction of the cursor is backwards
  4. a secondary range

In this case, the offset was not being added into the anchor. An example of a case for this would be inserting a new pair in insert mode with multiple single width cursors at the end of their respective lines in a CRLF document. This was fixed.

dead10ck avatar Sep 29 '22 20:09 dead10ck

@the-mikedavis or @archseer did you guys want anything else for this PR?

dead10ck avatar Oct 19 '22 17:10 dead10ck

This looks good to me but I'll defer the merge to archseer

the-mikedavis avatar Oct 19 '22 22:10 the-mikedavis

Looks good but there's one conflict to resolve now

archseer avatar Oct 20 '22 14:10 archseer

Done!

dead10ck avatar Oct 20 '22 14:10 dead10ck