Cleanup - fix various tests.

This commit is contained in:
Per Bothner
2023-05-17 18:37:27 -07:00
parent 2f7fe1189c
commit 67e968926c
12 changed files with 136 additions and 54 deletions
+10 -26
View File
@@ -530,16 +530,15 @@ export class InputHandler extends Disposable implements IInputHandler {
}
}
let precedingInfo = this._parser.precedingCodepoint === 0 ? 0
const precedingInfo = this._parser.precedingCodepoint === 0 ? 0
: this._parser.precedingJoinState;
// calculate print space
// expensive call, therefore we save width in line buffer
let currentInfo = this._unicodeService.charProperties(code, precedingInfo);
let chWidth = UnicodeService.extractWidth(currentInfo);
let shouldJoin = UnicodeService.extractShouldJoin(currentInfo);
const currentInfo = this._unicodeService.charProperties(code, precedingInfo);
chWidth = UnicodeService.extractWidth(currentInfo);
const shouldJoin = UnicodeService.extractShouldJoin(currentInfo);
const oldWidth = shouldJoin ? UnicodeService.extractWidth(precedingInfo) : 0;
this._parser.precedingCodepoint = code;
this._parser.precedingJoinState = currentInfo;
if (screenReaderMode) {
this._onA11yChar.fire(stringFromCodePoint(code));
}
@@ -575,7 +574,7 @@ export class InputHandler extends Disposable implements IInputHandler {
// Combining character widens 1 column to 2.
// Move old character to next line.
bufferRow.copyCellsFrom(oldRow as BufferLine,
oldCol, 0, oldWidth, false);
oldCol, 0, oldWidth, false);
}
// clear left over cells to the right
while (oldCol < cols) {
@@ -596,12 +595,12 @@ export class InputHandler extends Disposable implements IInputHandler {
// since they always follow a cell consuming char
// therefore we can test for this._activeBuffer.x to avoid overflow left
if (shouldJoin && this._activeBuffer.x) {
const offset = bufferRow.getWidth(this._activeBuffer.x - 1) ? 1 : 2
const offset = bufferRow.getWidth(this._activeBuffer.x - 1) ? 1 : 2;
// if empty cell after fullwidth, need to go 2 cells back
// it is save to step 2 cells back here
// since an empty cell is only set by fullwidth chars
bufferRow.addCodepointToCell(this._activeBuffer.x - offset,
code, chWidth);
code, chWidth);
this._activeBuffer.x += chWidth - oldWidth;
continue;
}
@@ -609,7 +608,7 @@ export class InputHandler extends Disposable implements IInputHandler {
// insert mode: move characters to right
if (insertMode) {
// right shift cells according to the width
bufferRow.insertCells(this._activeBuffer.x, chWidth, this._activeBuffer.getNullCell(curAttr), curAttr);
bufferRow.insertCells(this._activeBuffer.x, chWidth - oldWidth, this._activeBuffer.getNullCell(curAttr), curAttr);
// test last cell - since the last cell has only room for
// a halfwidth char any fullwidth shifted there is lost
// and will be set to empty cell
@@ -631,22 +630,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}
}
}
/*
// store last char in Parser.precedingCodepoint for REP to work correctly
// This needs to check whether:
// - fullwidth + surrogates: reset
// - combining: only base char gets carried on (bug in xterm?)
if (end - start > 0) {
bufferRow.loadCell(this._activeBuffer.x - 1, this._workCell);
if (this._workCell.getWidth() === 2 || this._workCell.getCode() > 0xFFFF) {
this._parser.precedingCodepoint = 0;
} else if (this._workCell.isCombined()) {
this._parser.precedingCodepoint = this._workCell.getChars().charCodeAt(0);
} else {
this._parser.precedingCodepoint = this._workCell.content;
}
}
*/
// handle wide chars: reset cell to the right if it is second cell of a wide char
if (this._activeBuffer.x < cols && end - start > 0 && bufferRow.getWidth(this._activeBuffer.x) === 0 && !bufferRow.hasContent(this._activeBuffer.x)) {
bufferRow.setCellFromCodePoint(this._activeBuffer.x, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
+11 -3
View File
@@ -170,9 +170,17 @@ export class MockUnicodeService implements IUnicodeService {
public onChange: IEvent<string> = new EventEmitter<string>().event;
public wcwidth = (codepoint: number): UnicodeCharWidth => this._provider.wcwidth(codepoint);
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
const w = this.wcwidth(codepoint);
const shouldJoin = w !== 0;
return UnicodeService.createPropertyValue(0, w, shouldJoin);
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);
}
public getStringCellWidth(s: string): number {
throw new Error('Method not implemented.');
+1 -1
View File
@@ -227,7 +227,7 @@ export class BufferLine implements IBufferLine {
* onto a leading char. Since we already set the attrs
* by the previous `setDataFromCodePoint` call, we can omit it here.
*/
public addCodepointToCell(index: number, codePoint: number, width: number): void {
public addCodepointToCell(index: number, codePoint: number, width: number): void {
let content = this._data[index * CELL_SIZE + Cell.CONTENT];
if (content & Content.IS_COMBINED_MASK) {
// we already have a combined string, simply add
+4 -7
View File
@@ -2,8 +2,7 @@
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { IUnicodeVersionProvider } from 'common/services/Services';
import { UnicodeCharProperties, UnicodeCharWidth } from 'common/services/Services';
import { IUnicodeVersionProvider, UnicodeCharProperties, UnicodeCharWidth } from 'common/services/Services';
import { UnicodeService } from 'common/services/UnicodeService';
const BMP_COMBINING = [
@@ -130,14 +129,12 @@ export class UnicodeV6 implements IUnicodeVersionProvider {
return 1;
}
charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
public charProperties(codepoint: number, preceding: UnicodeCharProperties): UnicodeCharProperties {
let width = this.wcwidth(codepoint);
let shouldJoin = width === 0;
let shouldJoin = width === 0 && preceding !== 0;
if (shouldJoin) {
let oldWidth = preceding === 0 ? 0
: UnicodeService.extractWidth(preceding);
const oldWidth = UnicodeService.extractWidth(preceding);
if (oldWidth === 0) {
width = 1;
shouldJoin = false;
} else if (oldWidth > width) {
width = oldWidth;
-1
View File
@@ -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');
+1 -1
View File
@@ -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));
}
}
+9 -2
View File
@@ -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);
}
}