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:
Per Bothner
2023-08-21 13:03:06 -07:00
parent 2204375788
commit e5a2ebda0e
3 changed files with 21 additions and 8 deletions
@@ -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) {