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

wanted_column now works with wide graphemes #26

Merged
merged 2 commits into from
Oct 31, 2019

Conversation

kandu
Copy link
Collaborator

@kandu kandu commented Oct 30, 2019

The wanted_column now works with wide graphemes.

Instead of recording the offset, the wanted_column value records the current column_display which is based on the width of the graphemes.

Every time a user goto prev_n or next_n lines, goto bol, eol etc it now calculates the offset at the given column_width and set the result offset as the new position.

Click to expand the GIFs before this patch

before
after this patch

after

@kandu kandu requested a review from a user October 30, 2019 17:03
@@ -74,3 +74,7 @@ val replace : t -> int -> int -> t -> t
(** [replace set offset length repl] replaces the subset at offset
[offset] and length [length] by [repl] in [set]. *)

val get_idx_by_width : t -> int -> int -> int
(** [get_idx_by_width set column_width] return the offset of the char at
Copy link

Choose a reason for hiding this comment

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

The spec in the documentation comment looks wrong; it has only two arguments while the function takes 3

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, doc comment is fixed now.

@ghost
Copy link

ghost commented Oct 31, 2019

Nice! The two gifs look the same to me BTW

@hhugo
Copy link
Contributor

hhugo commented Oct 31, 2019

Nice! The two gifs look the same to me BTW

They are actually different, on the first gif, the cursor always fall at the end of the second line.

@kandu
Copy link
Collaborator Author

kandu commented Oct 31, 2019

yeah, previously, wanted_column is counted based on the number of characters. so in the first gif, it always want to jump to the 6th character of line 2, which exceed the eol.
Then we move the cursor to "3", it then jump to the third character of line 2, "啊"

@ghost
Copy link

ghost commented Oct 31, 2019

Ah, indeed I missed that

Copy link

@ghost ghost 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!

@kandu
Copy link
Collaborator Author

kandu commented Oct 31, 2019

thank you

@kandu kandu merged commit 88fa88d into ocaml-community:master Oct 31, 2019
@kandu kandu deleted the wanted_column branch October 31, 2019 13:09
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.

2 participants