fix: dirty fix for char width

This commit is contained in:
Shibo Lyu 2025-01-28 17:21:59 +08:00
parent 4dd8121ebb
commit 7923680e80
3 changed files with 9 additions and 2 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@textplace/core", "name": "@textplace/core",
"version": "0.4.0", "version": "0.4.1",
"exports": "./mod.ts", "exports": "./mod.ts",
"imports": { "imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.3", "@deno/dnt": "jsr:@deno/dnt@^0.41.3",

View file

@ -10,5 +10,6 @@ export function getCharacterWidth(ch: string): number {
); );
} }
return unicodeWidth(ch); // TODO: Properly fix this.
return Math.min(unicodeWidth(ch), 2);
} }

View file

@ -32,6 +32,12 @@ Deno.test("getCharacterWidth CJK", () => {
assertThrows(() => getCharacterWidth("ヨスガノ")); assertThrows(() => getCharacterWidth("ヨスガノ"));
}); });
Deno.test("getCharacterWidth Emoji", () => {
assertEquals(getCharacterWidth("👋"), 2);
assertEquals(getCharacterWidth("🌲️"), 2);
assertEquals(getCharacterWidth("👨‍👩‍👧‍👦"), 2);
});
Deno.test("getCharacterWidth previously faulty cases", () => { Deno.test("getCharacterWidth previously faulty cases", () => {
assertEquals(getCharacterWidth("𤲶"), 2); assertEquals(getCharacterWidth("𤲶"), 2);
}); });