-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 emoji width #1951
Fix emoji width #1951
Conversation
@@ -76,6 +76,20 @@ describe('getStringCellWidth', function(): void { | |||
assert.equal(getStringCellWidth(s), sumWidths(terminal.buffer, 0, 1, '#')); | |||
}); | |||
// TODO: multiline tests once #1685 is resolved | |||
it('emojis', function(): void { | |||
const input = '😁😁😁😁😁😁#'; |
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.
I've never seen emojis in code before haha this is great
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.
I've never seen emojis in code before haha this is great
Actually there were a few and the failed test is one of them😂
Yes thats part of #1714. Unless we properly respect different Unicode versions we cannot make this work reliably. I have to vote against this patch here, as it only covers some chars while others are left out. Furthermore this will break with systems, that still use a lower Unicode version, like Ubuntu 16 or older OSX versions (before High Sierra). |
Problem
As described in #469 (comment), emoji width is 1 when added then displayed in half, and delete width is 2 when it is deleted which caused character in the left is deleted by mistake.
Conditions
\u55357
+\u56834
\u10060
.\u{200D}
, so'👩❤️💋👩'.length === 11
, when copy & paste in Chrome address, it becomes 👩 ❤️ 💋 👩 separated by\u8205
This only fix emoji width, IME support is WIP here #1890
Solution
Single 'string' width is calculated by
wcwidth
which doesn't consider emojis.By extending
getStringCellWidth
, it can calculate both single 'string' and normal string width, containing eitherwcwidth
standing characters and unicode emojis. Terminal should usegetStringCellWidth
other thanwcwidth
to cover emoji width calculation.References
https://mathiasbynens.be/notes/javascript-unicode
https://blog.jonnew.com/posts/poo-dot-length-equals-two
Testing
Buffer stringIndexToBufferIndex fullwidth combining with emoji - match emoji cell
. 'Lots of ¥\u0301 make me 😃.' is 3 lines interminal.buffer.lines.get(some_line_index)
like: