Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auto_pairs): fix auto pairs with crlf #1470

Merged
merged 1 commit into from
Jan 17, 2022

Conversation

dead10ck
Copy link
Member

Auto pairs were resulting in incorrect ranges in the selections when the line terminators are CRLF (i.e. Windows). It turns out this is because when we were checking if the selection was a single-width cursor, it incorrectly assumed that this would be a single char. This is not the case, as a cursor can cover a multi-code point grapheme. Therefore, we must instead explicitly work with and check graphemes to determine if the cursor should move or extend the selection.

Fixes #1436

@dead10ck
Copy link
Member Author

@CptPotato would you please be able to test this locally on your Windows machine and verify the fix?

Comment on lines 44 to 45
fern = "0.6"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two imports still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they were necessary for seeing logs with unit tests. Though it might be worthwhile to leave this out until we set up common unit testing code for things like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this for now, I personally either use a debugger or switch to println!() when debugging then remove it before commiting

@CptPotato
Copy link
Contributor

@CptPotato would you please be able to test this locally on your Windows machine and verify the fix?

I've only done a quick test but it seems to work for me now 👍

Copy link
Member

@archseer archseer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good otherwise, I've been trying to simplify this but haven't found a way yet. I think it might make things simpler if get_next_range is implemented per operation (open/close) since close always takes the if len_inserted == 0 path.

Comment on lines 44 to 45
fern = "0.6"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this for now, I personally either use a debugger or switch to println!() when debugging then remove it before commiting

Auto pairs were resulting in incorrect ranges in the resulting when the
line terminators are CRLF (i.e. Windows). It turns out this is because
when we were checking if the selection was a single-width cursor, it
incorrectly assumed that this would be a single char. This is not the
case, as a cursor can cover a multi-code point grapheme. Therefore,
we must instead explicitly work with and check graphemes to determine
if the cursor should move or extend the selection.

Fixes helix-editor#1436
@dead10ck
Copy link
Member Author

dead10ck commented Jan 16, 2022

Looks good otherwise, I've been trying to simplify this but haven't found a way yet.

Yeah, the function is bigger than I would like, but I also can't think of a good way to simplify it.

I think it might make things simpler if get_next_range is implemented per operation (open/close) since close always takes the if len_inserted == 0 path.

This is actually not true, because you can be inserting a closing character by itself, in which case it must be 1 with the current code, and shares logic with the open path.

And after we have more flexible configs a la #1418, it could theoretically be longer lengths from international keyboards, in which case it shares even more logic.

Let's remove this for now, I personally either use a debugger or switch to println!() when debugging then remove it before commiting

Ok, done. I had been using println!, but I tend to forget it's there when I go to make a debug build to test out changes, and then the renderer completely barfs and makes a bunch of garbled text because the debug output is printing to stdout and much hilarity ensues.

But yeah, this should be something in the testing harness as part of #115 instead of scattering logging code across the code base in random modules.

@archseer archseer merged commit 56a9ce5 into helix-editor:master Jan 17, 2022
@dead10ck dead10ck deleted the fix-auto-pairs-crlf branch January 18, 2022 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect auto pair at line ending
3 participants