Merge pull request #1543 from nikonso/fix-SelectionRenderLayer-state
Fix SelectionRenderLayer._state
This commit is contained in:
@@ -8,13 +8,14 @@ import { IColorSet, IRenderDimensions } from './Types';
|
|||||||
import { BaseRenderLayer } from './BaseRenderLayer';
|
import { BaseRenderLayer } from './BaseRenderLayer';
|
||||||
|
|
||||||
export class SelectionRenderLayer extends BaseRenderLayer {
|
export class SelectionRenderLayer extends BaseRenderLayer {
|
||||||
private _state: {start: [number, number], end: [number, number]};
|
private _state: { start: [number, number], end: [number, number], columnSelectMode: boolean };
|
||||||
|
|
||||||
constructor(container: HTMLElement, zIndex: number, colors: IColorSet) {
|
constructor(container: HTMLElement, zIndex: number, colors: IColorSet) {
|
||||||
super(container, 'selection', zIndex, true, colors);
|
super(container, 'selection', zIndex, true, colors);
|
||||||
this._state = {
|
this._state = {
|
||||||
start: null,
|
start: null,
|
||||||
end: null
|
end: null,
|
||||||
|
columnSelectMode: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +24,8 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
// Resizing the canvas discards the contents of the canvas so clear state
|
// Resizing the canvas discards the contents of the canvas so clear state
|
||||||
this._state = {
|
this._state = {
|
||||||
start: null,
|
start: null,
|
||||||
end: null
|
end: null,
|
||||||
|
columnSelectMode: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +33,8 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
if (this._state.start && this._state.end) {
|
if (this._state.start && this._state.end) {
|
||||||
this._state = {
|
this._state = {
|
||||||
start: null,
|
start: null,
|
||||||
end: null
|
end: null,
|
||||||
|
columnSelectMode: null
|
||||||
};
|
};
|
||||||
this.clearAll();
|
this.clearAll();
|
||||||
}
|
}
|
||||||
@@ -39,7 +42,7 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
|
|
||||||
public onSelectionChanged(terminal: ITerminal, start: [number, number], end: [number, number], columnSelectMode: boolean): void {
|
public onSelectionChanged(terminal: ITerminal, start: [number, number], end: [number, number], columnSelectMode: boolean): void {
|
||||||
// Selection has not changed
|
// Selection has not changed
|
||||||
if (this._state.start === start || this._state.end === end) {
|
if (!this._didStateChange(start, end, columnSelectMode)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +72,6 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
const width = end[0] - startCol;
|
const width = end[0] - startCol;
|
||||||
const height = viewportCappedEndRow - viewportCappedStartRow + 1;
|
const height = viewportCappedEndRow - viewportCappedStartRow + 1;
|
||||||
this.fillCells(startCol, viewportCappedStartRow, width, height);
|
this.fillCells(startCol, viewportCappedStartRow, width, height);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Draw first row
|
// Draw first row
|
||||||
const startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
|
const startCol = viewportStartRow === viewportCappedStartRow ? start[0] : 0;
|
||||||
@@ -91,5 +93,20 @@ export class SelectionRenderLayer extends BaseRenderLayer {
|
|||||||
// Save state for next render
|
// Save state for next render
|
||||||
this._state.start = [start[0], start[1]];
|
this._state.start = [start[0], start[1]];
|
||||||
this._state.end = [end[0], end[1]];
|
this._state.end = [end[0], end[1]];
|
||||||
|
this._state.columnSelectMode = columnSelectMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _didStateChange(start: [number, number], end: [number, number], columnSelectMode: boolean): boolean {
|
||||||
|
return !this._areCoordinatesEqual(start, this._state.start) ||
|
||||||
|
!this._areCoordinatesEqual(end, this._state.end) ||
|
||||||
|
columnSelectMode !== this._state.columnSelectMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _areCoordinatesEqual(coord1: [number, number], coord2: [number, number]): boolean {
|
||||||
|
if (!coord1 || !coord2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return coord1[0] === coord2[0] && coord1[1] === coord2[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user