Skip to content

Commit 13be985

Browse files
authored
Merge pull request xtermjs#4825 from PerBothner/setcell-refactor
Change setCellFromCodePoint API and rename to setCellFromCodepoint
2 parents a5646a5 + b0407e2 commit 13be985

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

src/common/InputHandler.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export class InputHandler extends Disposable implements IInputHandler {
519519

520520
// handle wide chars: reset start_cell-1 if we would overwrite the second cell of a wide char
521521
if (this._activeBuffer.x && end - start > 0 && bufferRow.getWidth(this._activeBuffer.x - 1) === 2) {
522-
bufferRow.setCellFromCodePoint(this._activeBuffer.x - 1, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
522+
bufferRow.setCellFromCodepoint(this._activeBuffer.x - 1, 0, 1, curAttr);
523523
}
524524

525525
let precedingJoinState = this._parser.precedingJoinState;
@@ -581,7 +581,7 @@ export class InputHandler extends Disposable implements IInputHandler {
581581
}
582582
// clear left over cells to the right
583583
while (oldCol < cols) {
584-
oldRow.setCellFromCodePoint(oldCol++, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
584+
oldRow.setCellFromCodepoint(oldCol++, 0, 1, curAttr);
585585
}
586586
} else {
587587
this._activeBuffer.x = cols - 1;
@@ -605,33 +605,33 @@ export class InputHandler extends Disposable implements IInputHandler {
605605
bufferRow.addCodepointToCell(this._activeBuffer.x - offset,
606606
code, chWidth);
607607
for (let delta = chWidth - oldWidth; --delta >= 0; ) {
608-
bufferRow.setCellFromCodePoint(this._activeBuffer.x++, 0, 0, curAttr.fg, curAttr.bg, curAttr.extended);
608+
bufferRow.setCellFromCodepoint(this._activeBuffer.x++, 0, 0, curAttr);
609609
}
610610
continue;
611611
}
612612

613613
// insert mode: move characters to right
614614
if (insertMode) {
615615
// right shift cells according to the width
616-
bufferRow.insertCells(this._activeBuffer.x, chWidth - oldWidth, this._activeBuffer.getNullCell(curAttr), curAttr);
616+
bufferRow.insertCells(this._activeBuffer.x, chWidth - oldWidth, this._activeBuffer.getNullCell(curAttr));
617617
// test last cell - since the last cell has only room for
618618
// a halfwidth char any fullwidth shifted there is lost
619619
// and will be set to empty cell
620620
if (bufferRow.getWidth(cols - 1) === 2) {
621-
bufferRow.setCellFromCodePoint(cols - 1, NULL_CELL_CODE, NULL_CELL_WIDTH, curAttr.fg, curAttr.bg, curAttr.extended);
621+
bufferRow.setCellFromCodepoint(cols - 1, NULL_CELL_CODE, NULL_CELL_WIDTH, curAttr);
622622
}
623623
}
624624

625625
// write current char to buffer and advance cursor
626-
bufferRow.setCellFromCodePoint(this._activeBuffer.x++, code, chWidth, curAttr.fg, curAttr.bg, curAttr.extended);
626+
bufferRow.setCellFromCodepoint(this._activeBuffer.x++, code, chWidth, curAttr);
627627

628628
// fullwidth char - also set next cell to placeholder stub and advance cursor
629629
// for graphemes bigger than fullwidth we can simply loop to zero
630630
// we already made sure above, that this._activeBuffer.x + chWidth will not overflow right
631631
if (chWidth > 0) {
632632
while (--chWidth) {
633633
// other than a regular empty cell a cell following a wide char has no width
634-
bufferRow.setCellFromCodePoint(this._activeBuffer.x++, 0, 0, curAttr.fg, curAttr.bg, curAttr.extended);
634+
bufferRow.setCellFromCodepoint(this._activeBuffer.x++, 0, 0, curAttr);
635635
}
636636
}
637637
}
@@ -640,7 +640,7 @@ export class InputHandler extends Disposable implements IInputHandler {
640640

641641
// handle wide chars: reset cell to the right if it is second cell of a wide char
642642
if (this._activeBuffer.x < cols && end - start > 0 && bufferRow.getWidth(this._activeBuffer.x) === 0 && !bufferRow.hasContent(this._activeBuffer.x)) {
643-
bufferRow.setCellFromCodePoint(this._activeBuffer.x, 0, 1, curAttr.fg, curAttr.bg, curAttr.extended);
643+
bufferRow.setCellFromCodepoint(this._activeBuffer.x, 0, 1, curAttr);
644644
}
645645

646646
this._dirtyRowTracker.markDirty(this._activeBuffer.y);
@@ -1145,7 +1145,6 @@ export class InputHandler extends Disposable implements IInputHandler {
11451145
start,
11461146
end,
11471147
this._activeBuffer.getNullCell(this._eraseAttrData()),
1148-
this._eraseAttrData(),
11491148
respectProtect
11501149
);
11511150
if (clearWrap) {
@@ -1366,8 +1365,7 @@ export class InputHandler extends Disposable implements IInputHandler {
13661365
line.insertCells(
13671366
this._activeBuffer.x,
13681367
params.params[0] || 1,
1369-
this._activeBuffer.getNullCell(this._eraseAttrData()),
1370-
this._eraseAttrData()
1368+
this._activeBuffer.getNullCell(this._eraseAttrData())
13711369
);
13721370
this._dirtyRowTracker.markDirty(this._activeBuffer.y);
13731371
}
@@ -1393,8 +1391,7 @@ export class InputHandler extends Disposable implements IInputHandler {
13931391
line.deleteCells(
13941392
this._activeBuffer.x,
13951393
params.params[0] || 1,
1396-
this._activeBuffer.getNullCell(this._eraseAttrData()),
1397-
this._eraseAttrData()
1394+
this._activeBuffer.getNullCell(this._eraseAttrData())
13981395
);
13991396
this._dirtyRowTracker.markDirty(this._activeBuffer.y);
14001397
}
@@ -1461,7 +1458,7 @@ export class InputHandler extends Disposable implements IInputHandler {
14611458
const param = params.params[0] || 1;
14621459
for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
14631460
const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1464-
line.deleteCells(0, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1461+
line.deleteCells(0, param, this._activeBuffer.getNullCell(this._eraseAttrData()));
14651462
line.isWrapped = false;
14661463
}
14671464
this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
@@ -1494,7 +1491,7 @@ export class InputHandler extends Disposable implements IInputHandler {
14941491
const param = params.params[0] || 1;
14951492
for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
14961493
const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1497-
line.insertCells(0, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1494+
line.insertCells(0, param, this._activeBuffer.getNullCell(this._eraseAttrData()));
14981495
line.isWrapped = false;
14991496
}
15001497
this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
@@ -1517,7 +1514,7 @@ export class InputHandler extends Disposable implements IInputHandler {
15171514
const param = params.params[0] || 1;
15181515
for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
15191516
const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1520-
line.insertCells(this._activeBuffer.x, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1517+
line.insertCells(this._activeBuffer.x, param, this._activeBuffer.getNullCell(this._eraseAttrData()));
15211518
line.isWrapped = false;
15221519
}
15231520
this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
@@ -1540,7 +1537,7 @@ export class InputHandler extends Disposable implements IInputHandler {
15401537
const param = params.params[0] || 1;
15411538
for (let y = this._activeBuffer.scrollTop; y <= this._activeBuffer.scrollBottom; ++y) {
15421539
const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
1543-
line.deleteCells(this._activeBuffer.x, param, this._activeBuffer.getNullCell(this._eraseAttrData()), this._eraseAttrData());
1540+
line.deleteCells(this._activeBuffer.x, param, this._activeBuffer.getNullCell(this._eraseAttrData()));
15441541
line.isWrapped = false;
15451542
}
15461543
this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop, this._activeBuffer.scrollBottom);
@@ -1562,8 +1559,7 @@ export class InputHandler extends Disposable implements IInputHandler {
15621559
line.replaceCells(
15631560
this._activeBuffer.x,
15641561
this._activeBuffer.x + (params.params[0] || 1),
1565-
this._activeBuffer.getNullCell(this._eraseAttrData()),
1566-
this._eraseAttrData()
1562+
this._activeBuffer.getNullCell(this._eraseAttrData())
15671563
);
15681564
this._dirtyRowTracker.markDirty(this._activeBuffer.y);
15691565
}

src/common/Types.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ export interface IBufferLine {
235235
set(index: number, value: CharData): void;
236236
loadCell(index: number, cell: ICellData): ICellData;
237237
setCell(index: number, cell: ICellData): void;
238-
setCellFromCodePoint(index: number, codePoint: number, width: number, fg: number, bg: number, eAttrs: IExtendedAttrs): void;
238+
setCellFromCodepoint(index: number, codePoint: number, width: number, attrs: IAttributeData): void;
239239
addCodepointToCell(index: number, codePoint: number, width: number): void;
240-
insertCells(pos: number, n: number, ch: ICellData, eraseAttr?: IAttributeData): void;
241-
deleteCells(pos: number, n: number, fill: ICellData, eraseAttr?: IAttributeData): void;
242-
replaceCells(start: number, end: number, fill: ICellData, eraseAttr?: IAttributeData, respectProtect?: boolean): void;
240+
insertCells(pos: number, n: number, ch: ICellData): void;
241+
deleteCells(pos: number, n: number, fill: ICellData): void;
242+
replaceCells(start: number, end: number, fill: ICellData, respectProtect?: boolean): void;
243243
resize(cols: number, fill: ICellData): boolean;
244244
cleanupMemory(): number;
245245
fill(fillCellData: ICellData, respectProtect?: boolean): void;

src/common/buffer/BufferLine.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { CharData, IAttributeData, IBufferLine, ICellData, IExtendedAttrs } from 'common/Types';
7-
import { AttributeData, ExtendedAttrs } from 'common/buffer/AttributeData';
7+
import { AttributeData } from 'common/buffer/AttributeData';
88
import { CellData } from 'common/buffer/CellData';
99
import { Attributes, BgFlags, CHAR_DATA_ATTR_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, Content, NULL_CELL_CHAR, NULL_CELL_CODE, NULL_CELL_WIDTH, WHITESPACE_CELL_CHAR } from 'common/buffer/Constants';
1010
import { stringFromCodePoint } from 'common/input/TextDecoder';
@@ -212,13 +212,13 @@ export class BufferLine implements IBufferLine {
212212
* Since the input handler see the incoming chars as UTF32 codepoints,
213213
* it gets an optimized access method.
214214
*/
215-
public setCellFromCodePoint(index: number, codePoint: number, width: number, fg: number, bg: number, eAttrs: IExtendedAttrs): void {
216-
if (bg & BgFlags.HAS_EXTENDED) {
217-
this._extendedAttrs[index] = eAttrs;
215+
public setCellFromCodepoint(index: number, codePoint: number, width: number, attrs: IAttributeData): void {
216+
if (attrs.bg & BgFlags.HAS_EXTENDED) {
217+
this._extendedAttrs[index] = attrs.extended;
218218
}
219219
this._data[index * CELL_SIZE + Cell.CONTENT] = codePoint | (width << Content.WIDTH_SHIFT);
220-
this._data[index * CELL_SIZE + Cell.FG] = fg;
221-
this._data[index * CELL_SIZE + Cell.BG] = bg;
220+
this._data[index * CELL_SIZE + Cell.FG] = attrs.fg;
221+
this._data[index * CELL_SIZE + Cell.BG] = attrs.bg;
222222
}
223223

224224
/**
@@ -253,12 +253,12 @@ export class BufferLine implements IBufferLine {
253253
this._data[index * CELL_SIZE + Cell.CONTENT] = content;
254254
}
255255

256-
public insertCells(pos: number, n: number, fillCellData: ICellData, eraseAttr?: IAttributeData): void {
256+
public insertCells(pos: number, n: number, fillCellData: ICellData): void {
257257
pos %= this.length;
258258

259259
// handle fullwidth at pos: reset cell one to the left if pos is second cell of a wide char
260260
if (pos && this.getWidth(pos - 1) === 2) {
261-
this.setCellFromCodePoint(pos - 1, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
261+
this.setCellFromCodepoint(pos - 1, 0, 1, fillCellData);
262262
}
263263

264264
if (n < this.length - pos) {
@@ -277,11 +277,11 @@ export class BufferLine implements IBufferLine {
277277

278278
// handle fullwidth at line end: reset last cell if it is first cell of a wide char
279279
if (this.getWidth(this.length - 1) === 2) {
280-
this.setCellFromCodePoint(this.length - 1, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
280+
this.setCellFromCodepoint(this.length - 1, 0, 1, fillCellData);
281281
}
282282
}
283283

284-
public deleteCells(pos: number, n: number, fillCellData: ICellData, eraseAttr?: IAttributeData): void {
284+
public deleteCells(pos: number, n: number, fillCellData: ICellData): void {
285285
pos %= this.length;
286286
if (n < this.length - pos) {
287287
const cell = new CellData();
@@ -301,21 +301,21 @@ export class BufferLine implements IBufferLine {
301301
// - reset pos-1 if wide char
302302
// - reset pos if width==0 (previous second cell of a wide char)
303303
if (pos && this.getWidth(pos - 1) === 2) {
304-
this.setCellFromCodePoint(pos - 1, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
304+
this.setCellFromCodepoint(pos - 1, 0, 1, fillCellData);
305305
}
306306
if (this.getWidth(pos) === 0 && !this.hasContent(pos)) {
307-
this.setCellFromCodePoint(pos, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
307+
this.setCellFromCodepoint(pos, 0, 1, fillCellData);
308308
}
309309
}
310310

311-
public replaceCells(start: number, end: number, fillCellData: ICellData, eraseAttr?: IAttributeData, respectProtect: boolean = false): void {
311+
public replaceCells(start: number, end: number, fillCellData: ICellData, respectProtect: boolean = false): void {
312312
// full branching on respectProtect==true, hopefully getting fast JIT for standard case
313313
if (respectProtect) {
314314
if (start && this.getWidth(start - 1) === 2 && !this.isProtected(start - 1)) {
315-
this.setCellFromCodePoint(start - 1, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
315+
this.setCellFromCodepoint(start - 1, 0, 1, fillCellData);
316316
}
317317
if (end < this.length && this.getWidth(end - 1) === 2 && !this.isProtected(end)) {
318-
this.setCellFromCodePoint(end, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
318+
this.setCellFromCodepoint(end, 0, 1, fillCellData);
319319
}
320320
while (start < end && start < this.length) {
321321
if (!this.isProtected(start)) {
@@ -328,11 +328,11 @@ export class BufferLine implements IBufferLine {
328328

329329
// handle fullwidth at start: reset cell one to the left if start is second cell of a wide char
330330
if (start && this.getWidth(start - 1) === 2) {
331-
this.setCellFromCodePoint(start - 1, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
331+
this.setCellFromCodepoint(start - 1, 0, 1, fillCellData);
332332
}
333333
// handle fullwidth at last cell + 1: reset to empty cell if it is second part of a wide char
334334
if (end < this.length && this.getWidth(end - 1) === 2) {
335-
this.setCellFromCodePoint(end, 0, 1, eraseAttr?.fg || 0, eraseAttr?.bg || 0, eraseAttr?.extended || new ExtendedAttrs());
335+
this.setCellFromCodepoint(end, 0, 1, fillCellData);
336336
}
337337

338338
while (start < end && start < this.length) {

0 commit comments

Comments
 (0)