From 7f073beb480d087cad8be1dd8a051ac5671c672a Mon Sep 17 00:00:00 2001 From: fisker Date: Mon, 1 Sep 2025 11:36:56 +0800 Subject: [PATCH 1/2] Improve `isDoubleWidthEmojiCluster` --- index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index dec7c1e..5f1475c 100644 --- a/index.js +++ b/index.js @@ -32,16 +32,26 @@ function isZeroWidthCluster(segment) { } function isDoubleWidthEmojiCluster(segment) { + const hasVs16 = segment.includes('\uFE0F'); + + if (hasVs16) { + return true; + } + const visible = baseVisible(segment); const baseScalar = visible.codePointAt(0); const baseChar = String.fromCodePoint(baseScalar); const baseIsEmojiPresentation = emojiPresentationRegex.test(baseChar); - const hasVs16 = segment.includes('\uFE0F'); const hasVs15 = segment.includes('\uFE0E'); + + if (baseIsEmojiPresentation && !hasVs15) { + return true + } + const codePointCount = [...segment].length; const multiScalarMeaningful = codePointCount > 1 && !(codePointCount === 2 && hasVs15 && !hasVs16); - return hasVs16 || (baseIsEmojiPresentation && !hasVs15) || multiScalarMeaningful; + return multiScalarMeaningful; } function trailingHalfwidthWidth(segment, eastAsianWidthOptions) { From dc64f1168428601b94c3828267ddce849d4ef4f5 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 1 Sep 2025 11:48:24 +0800 Subject: [PATCH 2/2] Fix formatting issue in index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5f1475c..d72d5e9 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ function isDoubleWidthEmojiCluster(segment) { const hasVs15 = segment.includes('\uFE0E'); if (baseIsEmojiPresentation && !hasVs15) { - return true + return true; } const codePointCount = [...segment].length;