We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 595ff27 commit f86f253Copy full SHA for f86f253
2 files changed
frontend/__tests__/utils/strings.spec.ts
@@ -474,14 +474,14 @@ describe("string utils", () => {
474
["\u2003", 0x2003, "em space", true],
475
["\u2009", 0x2009, "thin space", true],
476
[" ", 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],
482
483
// Should return false for other characters
484
["\t", 0x0009, "tab", false],
- ["\u00A0", 0x00a0, "non-breaking space", false],
- ["\u2007", 0x2007, "figure space", false],
- ["\u2008", 0x2008, "punctuation space", false],
- ["\u200A", 0x200a, "hair space", false],
- ["", 0x200b, "zero-width space", false],
485
["a", 0x0061, "letter a", false],
486
["A", 0x0041, "letter A", false],
487
["1", 0x0031, "digit 1", false],
frontend/src/ts/utils/strings.ts
@@ -336,19 +336,24 @@ export function isSpace(char: string): boolean {
336
const codePoint = char.codePointAt(0);
337
if (codePoint === undefined) return false;
338
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
- );
+ const spaces = new Set([
+ 0x0020, // Regular space (spacebar)
+ 0x2002, // En space (Option+Space on Mac)
+ 0x2003, // Em space (Option+Shift+Space on Mac)
+ 0x2009, // Thin space (various input methods)
+ 0x3000, // Ideographic space (CJK input methods)
+ 0x00a0, // Non-breaking space (Alt+0160 on Windows, Option+Space on Mac)
+ 0x1680, // Ogham space mark (rare, but included for completeness)
+ 0x202f, // Narrow no-break space (various input methods)
+ 0xfeff, // Zero width no-break space (various input methods)
+ 0x2007, // Figure space (various input methods)
+ 0x2008, // Punctuation space (various input methods)
+ 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);
357
}
358
359
// Export testing utilities for unit tests
0 commit comments