Merge pull request #4519 from PerBothner/clusters

New unicode-graphemes addon.
This commit is contained in:
Daniel Imms
2023-09-12 13:56:27 -07:00
committed by GitHub
43 changed files with 1480 additions and 103 deletions
+18 -4
View File
@@ -4,8 +4,8 @@
*/
import { IUnicodeVersionProvider } from 'xterm';
type CharWidth = 0 | 1 | 2;
import { UnicodeCharProperties, UnicodeCharWidth } from 'common/services/Services';
import { UnicodeService } from 'common/services/UnicodeService';
const BMP_COMBINING = [
[0x0300, 0x036F], [0x0483, 0x0489], [0x0591, 0x05BD],
@@ -210,12 +210,26 @@ export class UnicodeV11 implements IUnicodeVersionProvider {
}
}
public wcwidth(num: number): CharWidth {
public wcwidth(num: number): UnicodeCharWidth {
if (num < 32) return 0;
if (num < 127) return 1;
if (num < 65536) return table[num] as CharWidth;
if (num < 65536) return table[num] as UnicodeCharWidth;
if (bisearch(num, HIGH_COMBINING)) return 0;
if (bisearch(num, HIGH_WIDE)) return 2;
return 1;
}
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
let width = this.wcwidth(codepoint);
let shouldJoin = width === 0 && preceding !== 0;
if (shouldJoin) {
const oldWidth = UnicodeService.extractWidth(preceding);
if (oldWidth === 0) {
shouldJoin = false;
} else if (oldWidth > width) {
width = oldWidth;
}
}
return UnicodeService.createPropertyValue(0, width, shouldJoin);
}
}
@@ -36,7 +36,7 @@ describe('Unicode11Addon', () => {
window.term.loadAddon(window.unicode11);
`);
// should have loaded '11'
assert.deepEqual(await page.evaluate(`window.term.unicode.versions`), ['6', '11']);
assert.deepEqual((await page.evaluate(`window.term.unicode.versions`) as string[]).includes('11'), true);
// switch should not throw
await page.evaluate(`window.term.unicode.activeVersion = '11';`);
assert.deepEqual(await page.evaluate(`window.term.unicode.activeVersion`), '11');