Handle zero-width marks in string width (#19538)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
e46109d602
commit
fdd6965b2e
6 files changed
+64
-10
No files matched your search
@@ -8,6 +8,8 @@ import {
|
||||
import { isNarrowEmojiCharacter } from "narrow-emojis";
|
||||
|
||||
const notAsciiRegex = /[^\x20-\x7F]/;
|
||||
// Exclude [`Spacing Mark`](https://www.compart.com/en/unicode/category/Mc) because spacing marks contribute horizontal width.
|
||||
const zeroWidthMarkRegex = /[\p{Nonspacing_Mark}\p{Enclosing_Mark}]/u;
|
||||
|
||||
// Similar to https://github.com/sindresorhus/string-width
|
||||
// We don't strip ansi, always treat ambiguous width characters as having narrow width.
|
||||
@@ -42,13 +44,8 @@ function getStringWidth(text) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore combining characters
|
||||
if (codePoint >= 0x300 && codePoint <= 0x36f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore Variation Selectors
|
||||
if (codePoint >= 0xfe00 && codePoint <= 0xfe0f) {
|
||||
// Ignore zero-width marks, including combining marks and variation selectors
|
||||
if (zeroWidthMarkRegex.test(character)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user