diff --git a/deno.json b/deno.json index 2ac2e2b..ffdf2b3 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@textplace/core", - "version": "0.4.0", + "version": "0.4.1", "exports": "./mod.ts", "imports": { "@deno/dnt": "jsr:@deno/dnt@^0.41.3", diff --git a/logic/character.ts b/logic/character.ts index 074001d..2d58dac 100644 --- a/logic/character.ts +++ b/logic/character.ts @@ -10,5 +10,6 @@ export function getCharacterWidth(ch: string): number { ); } - return unicodeWidth(ch); + // TODO: Properly fix this. + return Math.min(unicodeWidth(ch), 2); } diff --git a/tests/character.test.ts b/tests/character.test.ts index d1330f9..c8e3a65 100644 --- a/tests/character.test.ts +++ b/tests/character.test.ts @@ -32,6 +32,12 @@ Deno.test("getCharacterWidth CJK", () => { assertThrows(() => getCharacterWidth("ใƒจใ‚นใ‚ฌใƒŽ")); }); +Deno.test("getCharacterWidth Emoji", () => { + assertEquals(getCharacterWidth("๐Ÿ‘‹"), 2); + assertEquals(getCharacterWidth("๐ŸŒฒ๏ธ"), 2); + assertEquals(getCharacterWidth("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"), 2); +}); + Deno.test("getCharacterWidth previously faulty cases", () => { assertEquals(getCharacterWidth("๐คฒถ"), 2); });