-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
More closely match Neovim's word-movement semantics #12160
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
Open
kirawi
wants to merge
1
commit into
helix-editor:master
Choose a base branch
from
kirawi:motion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this differentation? I don't see us ever inspecting the category, we only seem to check wether something is a word character or not.
In general it's not clear to me what the goal of this PR is, is just to treat
as word characters? I can't read ow write these languages but generally the rust unicode characterization is quite accurate and I don't think we should be blindly adding to it (also adds overhead to one of the most commonly called functions in the codebase).
If you take a look here:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5e40c4176f08205842feb4f39b3a5399
some of the codepoint ranges covered here already fully fall under alpha_numeric and for those that don't I am skeptical they make sense to include. For example some output from the script:
I wouldn't want to just blindly copy what nvim is doing. Historically unicode treatment is a mess. If we are going to go beyond unicode standard definition of alphanumeric then I would like to see the ranges selected so they don't overlap with our current definition and an explanation why these ranges are necessary in a comment.
My gut feeling on this is that the only thing where this more complex unicode word definition actually makes sense is for movements that care about word boundaries/segmentation (like miw and e/b/w). Proper Unicode segmentation is quite a bit more complex than adding a couple characters here (unicode-segmentation has that builtin, it's not a trivial algorithm: https://docs.rs/unicode-segmentation/latest/src/unicode_segmentation/word.rs.html#202)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what this change does is that when we check word boundaries for w/b, we check if the previous and next char have the same category. The subcategory adds differentiation so they are treated as separate words
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok I didn't see it show up in the diff but the comparison is different I suppose. I still wonder if we shouldn't just do proper word segmentation in the places where this is used
Could we just leave
char_is_word
as is and only change the categorization? The function is very frequently used and I dont' really want to change itUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Proper word segmentation" as performed by
unicode_segmentation
simply treats each CJK character as its own "word". It is valid for soft-wrapping, but is extremely useless for editing. Example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=520d54ca25851bd7b5e19c1b800f1c4eThis produces
["吾", "輩", "は", "猫", "で", "あ", "る"]
, which is, as you can probably guess, extremely useless. The categorization proposed by this PR would instead produce["吾輩", "は", "猫", "である"]
, which is much more useful for actually writing in the language.This does however only improve the situation for Japanese. For Chinese and Korean, useful segmentations can only be produced through the use of a dictionary, since those languages each use only a single script. This could be a use case for the proposed plugin system, so people who don't edit text in those language won't get any of the bloat.