Cleanup - fix various tests.
This commit is contained in:
@@ -296,7 +296,6 @@ export interface IOscLinkService {
|
||||
|
||||
/** Width and Grapheme_Cluster_Break properties of a character. */
|
||||
export type UnicodeCharProperties = number;
|
||||
export const UnicodeInitialProperties: UnicodeCharProperties = 0; // UNEEDED?
|
||||
export type UnicodeCharWidth = 0 | 1 | 2;
|
||||
|
||||
export const IUnicodeService = createDecorator<IUnicodeService>('UnicodeService');
|
||||
|
||||
@@ -12,7 +12,7 @@ class DummyProvider implements IUnicodeVersionProvider {
|
||||
public wcwidth(n: number): 0 | 1 | 2 {
|
||||
return 2;
|
||||
}
|
||||
charProperties(codepoint: number): number {
|
||||
public charProperties(codepoint: number): number {
|
||||
return UnicodeService.createPropertyValue(0, this.wcwidth(codepoint));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ export class UnicodeService implements IUnicodeService {
|
||||
|
||||
public getStringCellWidth(s: string): number {
|
||||
let result = 0;
|
||||
let precedingInfo = 0;
|
||||
const length = s.length;
|
||||
for (let i = 0; i < length; ++i) {
|
||||
let code = s.charCodeAt(i);
|
||||
@@ -92,12 +93,18 @@ export class UnicodeService implements IUnicodeService {
|
||||
result += this.wcwidth(second);
|
||||
}
|
||||
}
|
||||
result += this.wcwidth(code);
|
||||
const currentInfo = this.charProperties(code, precedingInfo);
|
||||
let chWidth = UnicodeService.extractWidth(currentInfo);
|
||||
if (UnicodeService.extractShouldJoin(currentInfo)) {
|
||||
chWidth -= UnicodeService.extractWidth(precedingInfo);
|
||||
}
|
||||
result += chWidth;
|
||||
precedingInfo = currentInfo;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
|
||||
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
|
||||
return this._activeProvider.charProperties(codepoint, preceding);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user