diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-04-05 09:42:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-05 09:42:00 +0800 |
commit | e8785c2e94508eeabf6ff63e1fe1bcaecceef946 (patch) | |
tree | 95550a4242171634e6fda593be9c757ffeb70ecc /test/functional/ui/diff_spec.lua | |
parent | 1e1384b6dd29c071ed76e4e2ed233511404bae72 (diff) | |
download | rneovim-e8785c2e94508eeabf6ff63e1fe1bcaecceef946.tar.gz rneovim-e8785c2e94508eeabf6ff63e1fe1bcaecceef946.tar.bz2 rneovim-e8785c2e94508eeabf6ff63e1fe1bcaecceef946.zip |
vim-patch:9.1.1276: inline word diff treats multibyte chars as word char (#33323)
Problem: inline word diff treats multibyte chars as word char
(after 9.1.1243)
Solution: treat all non-alphanumeric characters as non-word characters
(Yee Cheng Chin)
Previously inline word diff simply used Vim's definition of keyword to
determine what is a word, which leads to multi-byte character classes
such as emojis and CJK (Chinese/Japanese/Korean) characters all
classifying as word characters, leading to entire sentences being
grouped as a single word which does not provide meaningful information
in a diff highlight.
Fix this by treating all non-alphanumeric characters (with class number
above 2) as non-word characters, as there is usually no benefit in using
word diff on them. These include CJK characters, emojis, and also
subscript/superscript numbers. Meanwhile, multi-byte characters like
Cyrillic and Greek letters will still continue to considered as words.
Note that this is slightly inconsistent with how words are defined
elsewhere, as Vim usually considers any character with class >=2 to be
a "word".
related: vim/vim#16881 (diff inline highlight)
closes: vim/vim#17050
https://github.com/vim/vim/commit/9aa120f7ada592ed03b37f4de8ee413c5385f123
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
Diffstat (limited to 'test/functional/ui/diff_spec.lua')
-rw-r--r-- | test/functional/ui/diff_spec.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index 223622eb6b..21174eaa45 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -2485,6 +2485,22 @@ it('diff mode inline highlighting', function() command('windo set iskeyword& | 1wincmd w') + screen:try_resize(75, 20) + command('wincmd =') + -- word diff: test handling of multi-byte characters. Only alphanumeric chars + -- (e.g. Greek alphabet, but not CJK/emoji) count as words. + WriteDiffFiles( + '🚀⛵️一二三ひらがなΔέλτα Δelta foobar', + '🚀🛸一二四ひらなδέλτα δelta foobar' + ) + command('set diffopt=internal,filler diffopt+=inline:word') + screen:expect([[ + {7: }{4:^🚀}{27:⛵️}{4:一二}{27:三}{4:ひら}{100:が}{4:な}{27:Δέλτα}{4: }{27:Δelta}{4: fooba}│{7: }{4:🚀}{27:🛸}{4:一二}{27:四}{4:ひらな}{27:δέλτα}{4: }{27:δelta}{4: foobar }| + {1:~ }│{1:~ }|*17 + {3:Xdifile1 }{2:Xdifile2 }| + | + ]]) + screen:try_resize(69, 20) command('wincmd =') -- char diff: should slide highlight to whitespace boundary if possible for |