Skip to content

Commit f86f253

Browse files
committed
fix: non-breaking space behaving like a character
1 parent 595ff27 commit f86f253

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

frontend/__tests__/utils/strings.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,14 @@ describe("string utils", () => {
474474
["\u2003", 0x2003, "em space", true],
475475
["\u2009", 0x2009, "thin space", true],
476476
[" ", 0x3000, "ideographic space", true],
477+
["\u00A0", 0x00a0, "non-breaking space", true],
478+
["\u2007", 0x2007, "figure space", true],
479+
["\u2008", 0x2008, "punctuation space", true],
480+
["\u200A", 0x200a, "hair space", true],
481+
["​", 0x200b, "zero-width space", true],
477482

478483
// Should return false for other characters
479484
["\t", 0x0009, "tab", false],
480-
["\u00A0", 0x00a0, "non-breaking space", false],
481-
["\u2007", 0x2007, "figure space", false],
482-
["\u2008", 0x2008, "punctuation space", false],
483-
["\u200A", 0x200a, "hair space", false],
484-
["​", 0x200b, "zero-width space", false],
485485
["a", 0x0061, "letter a", false],
486486
["A", 0x0041, "letter A", false],
487487
["1", 0x0031, "digit 1", false],

frontend/src/ts/utils/strings.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,24 @@ export function isSpace(char: string): boolean {
336336
const codePoint = char.codePointAt(0);
337337
if (codePoint === undefined) return false;
338338

339-
// Directly typable spaces:
340-
// U+0020 - Regular space (spacebar)
341-
// U+2002 - En space (Option+Space on Mac)
342-
// U+2003 - Em space (Option+Shift+Space on Mac)
343-
// U+2009 - Thin space (various input methods)
344-
// U+3000 - Ideographic space (CJK input methods)
345-
return (
346-
codePoint === 0x0020 ||
347-
codePoint === 0x2002 ||
348-
codePoint === 0x2003 ||
349-
codePoint === 0x2009 ||
350-
codePoint === 0x3000
351-
);
339+
const spaces = new Set([
340+
0x0020, // Regular space (spacebar)
341+
0x2002, // En space (Option+Space on Mac)
342+
0x2003, // Em space (Option+Shift+Space on Mac)
343+
0x2009, // Thin space (various input methods)
344+
0x3000, // Ideographic space (CJK input methods)
345+
0x00a0, // Non-breaking space (Alt+0160 on Windows, Option+Space on Mac)
346+
0x1680, // Ogham space mark (rare, but included for completeness)
347+
0x202f, // Narrow no-break space (various input methods)
348+
0xfeff, // Zero width no-break space (various input methods)
349+
0x2007, // Figure space (various input methods)
350+
0x2008, // Punctuation space (various input methods)
351+
0x2004, // Three-per-em space (various input methods)
352+
0x200a, // Hair space (various input methods)
353+
0x200b, // Zero width space (various input methods)
354+
]);
355+
356+
return spaces.has(codePoint);
352357
}
353358

354359
// Export testing utilities for unit tests

0 commit comments

Comments
 (0)