mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Provide with "15" and "15-graphemes" UnicodeProviders
Th former doesn't support grapheme clusters, except the old-fashioned kind of simple modifiers. However, "15-graphemes" (with full cluster support) is the default.
This commit is contained in:
@@ -9,9 +9,13 @@ import { UnicodeService } from 'common/services/UnicodeService';
|
||||
import * as UC from './third-party/UnicodeProperties';
|
||||
|
||||
export class UnicodeGraphemeProvider implements IUnicodeVersionProvider {
|
||||
public readonly version = '15-graphemes';
|
||||
public readonly version;
|
||||
public ambiguousCharsAreWide: boolean = false;
|
||||
constructor() {
|
||||
public readonly handleGraphemes: boolean;
|
||||
|
||||
constructor(handleGraphemes: boolean = true) {
|
||||
this.version = handleGraphemes ? '15-graphemes' : '15';
|
||||
this.handleGraphemes = handleGraphemes;
|
||||
}
|
||||
|
||||
private static readonly _plainNarrowProperties: UnicodeCharProperties
|
||||
@@ -36,7 +40,11 @@ export class UnicodeGraphemeProvider implements IUnicodeVersionProvider {
|
||||
}
|
||||
if (preceding !== 0) {
|
||||
const oldWidth = UnicodeService.extractWidth(preceding);
|
||||
charInfo = UC.shouldJoin(UnicodeService.extractCharKind(preceding), charInfo);
|
||||
if (this.handleGraphemes) {
|
||||
charInfo = UC.shouldJoin(UnicodeService.extractCharKind(preceding), charInfo);
|
||||
} else {
|
||||
charInfo = w === 0 ? 1 : 0;
|
||||
}
|
||||
shouldJoin = charInfo > 0;
|
||||
if (shouldJoin) {
|
||||
if (oldWidth > w) {
|
||||
|
||||
@@ -10,17 +10,22 @@ import { UnicodeGraphemeProvider } from './UnicodeGraphemeProvider';
|
||||
|
||||
|
||||
export class UnicodeGraphemesAddon implements ITerminalAddon {
|
||||
private _provider?: UnicodeGraphemeProvider;
|
||||
private _provider15Graphemes?: UnicodeGraphemeProvider;
|
||||
private _provider15?: UnicodeGraphemeProvider;
|
||||
private _unicode?: IUnicodeHandling;
|
||||
private _oldVersion: string = '';
|
||||
|
||||
public activate(terminal: Terminal): void {
|
||||
if (! this._provider) {
|
||||
this._provider = new UnicodeGraphemeProvider();
|
||||
if (! this._provider15) {
|
||||
this._provider15 = new UnicodeGraphemeProvider(false);
|
||||
}
|
||||
if (! this._provider15Graphemes) {
|
||||
this._provider15Graphemes = new UnicodeGraphemeProvider(true);
|
||||
}
|
||||
const unicode = terminal.unicode;
|
||||
this._unicode = unicode;
|
||||
unicode.register(this._provider);
|
||||
unicode.register(this._provider15);
|
||||
unicode.register(this._provider15Graphemes);
|
||||
this._oldVersion = unicode.activeVersion;
|
||||
unicode.activeVersion = '15-graphemes';
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ describe('UnicodeGraphemesAddon', () => {
|
||||
window.term.loadAddon(window.unicode);
|
||||
`);
|
||||
// should have loaded '15-graphemes'
|
||||
assert.deepEqual(await page.evaluate(`window.term.unicode.versions`), ['6', ourVersion]);
|
||||
assert.deepEqual(await page.evaluate(`window.term.unicode.versions`), ['6', '15', '15-graphemes']);
|
||||
// switch should not throw
|
||||
await page.evaluate(`window.term.unicode.activeVersion = '${ourVersion}';`);
|
||||
assert.equal(await page.evaluate(`window.term.unicode.activeVersion`), ourVersion);
|
||||
|
||||
Reference in New Issue
Block a user