Merge pull request #3536 from silamon/isWrappedEraseInBufferline

Clear isWrapped in eraseBufferLine
This commit is contained in:
Daniel Imms
2021-12-21 08:39:03 -08:00
committed by GitHub
2 changed files with 62 additions and 12 deletions
+50
View File
@@ -386,6 +386,56 @@ describe('InputHandler', () => {
assert.equal(bufferService.buffer.lines.get(2)!.translateToString(false), Array(bufferService.cols + 1).join(' ')); assert.equal(bufferService.buffer.lines.get(2)!.translateToString(false), Array(bufferService.cols + 1).join(' '));
}); });
it('eraseInLine reflow', async () => {
const bufferService = new MockBufferService(80, 30);
const inputHandler = new TestInputHandler(
bufferService,
new MockCharsetService(),
new MockCoreService(),
new MockDirtyRowService(),
new MockLogService(),
new MockOptionsService(),
new MockCoreMouseService(),
new MockUnicodeService()
);
const resetToBaseState = async (): Promise<void> => {
// reset and add a wrapped line
bufferService.buffer.y = 0;
bufferService.buffer.x = 0;
await inputHandler.parseP(Array(bufferService.cols + 1).join('a')); // line 0
await inputHandler.parseP(Array(bufferService.cols + 10).join('a')); // line 1 and 2
for (let i = 3; i < bufferService.rows; ++i) await inputHandler.parseP(Array(bufferService.cols + 1).join('a'));
// confirm precondition that line 2 is wrapped
assert.equal(bufferService.buffer.lines.get(2)!.isWrapped, true);
};
// params[0] - erase from the cursor through the end of the row.
await resetToBaseState();
bufferService.buffer.y = 2;
bufferService.buffer.x = 40;
inputHandler.eraseInLine(Params.fromArray([0]));
assert.equal(bufferService.buffer.lines.get(2)!.isWrapped, true);
bufferService.buffer.y = 2;
bufferService.buffer.x = 0;
inputHandler.eraseInLine(Params.fromArray([0]));
assert.equal(bufferService.buffer.lines.get(2)!.isWrapped, false);
// params[1] - erase from the beginning of the line through the cursor
await resetToBaseState();
bufferService.buffer.y = 2;
bufferService.buffer.x = 40;
inputHandler.eraseInLine(Params.fromArray([1]));
assert.equal(bufferService.buffer.lines.get(2)!.isWrapped, true);
// params[2] - erase complete line
await resetToBaseState();
bufferService.buffer.y = 2;
bufferService.buffer.x = 40;
inputHandler.eraseInLine(Params.fromArray([2]));
assert.equal(bufferService.buffer.lines.get(2)!.isWrapped, false);
});
it('eraseInDisplay', async () => { it('eraseInDisplay', async () => {
const bufferService = new MockBufferService(80, 7); const bufferService = new MockBufferService(80, 7);
const inputHandler = new TestInputHandler( const inputHandler = new TestInputHandler(
+12 -12
View File
@@ -25,7 +25,7 @@ import { IBuffer } from 'common/buffer/Types';
/** /**
* Map collect to glevel. Used in `selectCharset`. * Map collect to glevel. Used in `selectCharset`.
*/ */
const GLEVEL: {[key: string]: number} = { '(': 0, ')': 1, '*': 2, '+': 3, '-': 1, '.': 2 }; const GLEVEL: { [key: string]: number } = { '(': 0, ')': 1, '*': 2, '+': 3, '-': 1, '.': 2 };
/** /**
* VT commands done by the parser - FIXME: move this to the parser? * VT commands done by the parser - FIXME: move this to the parser?
@@ -167,7 +167,7 @@ class DECRQSS implements IDcsHandler {
break; break;
case 'r': // DECSTBM case 'r': // DECSTBM
const pt = '' + (this._bufferService.buffer.scrollTop + 1) + const pt = '' + (this._bufferService.buffer.scrollTop + 1) +
';' + (this._bufferService.buffer.scrollBottom + 1) + 'r'; ';' + (this._bufferService.buffer.scrollBottom + 1) + 'r';
this._coreService.triggerDataEvent(`${C0.ESC}P1$r${pt}${C0.ESC}\\`); this._coreService.triggerDataEvent(`${C0.ESC}P1$r${pt}${C0.ESC}\\`);
break; break;
case 'm': // SGR case 'm': // SGR
@@ -175,7 +175,7 @@ class DECRQSS implements IDcsHandler {
this._coreService.triggerDataEvent(`${C0.ESC}P1$r0m${C0.ESC}\\`); this._coreService.triggerDataEvent(`${C0.ESC}P1$r0m${C0.ESC}\\`);
break; break;
case ' q': // DECSCUSR case ' q': // DECSCUSR
const STYLES: {[key: string]: number} = { 'block': 2, 'underline': 4, 'bar': 6 }; const STYLES: { [key: string]: number } = { 'block': 2, 'underline': 4, 'bar': 6 };
let style = STYLES[this._optionsService.options.cursorStyle]; let style = STYLES[this._optionsService.options.cursorStyle];
style -= this._optionsService.options.cursorBlink ? 1 : 0; style -= this._optionsService.options.cursorBlink ? 1 : 0;
this._coreService.triggerDataEvent(`${C0.ESC}P1$r${style} q${C0.ESC}\\`); this._coreService.triggerDataEvent(`${C0.ESC}P1$r${style} q${C0.ESC}\\`);
@@ -855,10 +855,9 @@ export class InputHandler extends Disposable implements IInputHandler {
* - any cursor movement sequence keeps working as expected * - any cursor movement sequence keeps working as expected
*/ */
if (this._activeBuffer.x === 0 if (this._activeBuffer.x === 0
&& this._activeBuffer.y > this._activeBuffer.scrollTop && this._activeBuffer.y > this._activeBuffer.scrollTop
&& this._activeBuffer.y <= this._activeBuffer.scrollBottom && this._activeBuffer.y <= this._activeBuffer.scrollBottom
&& this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)?.isWrapped) && this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)?.isWrapped) {
{
this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!.isWrapped = false; this._activeBuffer.lines.get(this._activeBuffer.ybase + this._activeBuffer.y)!.isWrapped = false;
this._activeBuffer.y--; this._activeBuffer.y--;
this._activeBuffer.x = this._bufferService.cols - 1; this._activeBuffer.x = this._bufferService.cols - 1;
@@ -1195,6 +1194,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @param y row index * @param y row index
* @param start first cell index to be erased * @param start first cell index to be erased
* @param end end - 1 is last erased cell * @param end end - 1 is last erased cell
* @param cleanWrap clear the isWrapped flag
*/ */
private _eraseInBufferLine(y: number, start: number, end: number, clearWrap: boolean = false): void { private _eraseInBufferLine(y: number, start: number, end: number, clearWrap: boolean = false): void {
const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!; const line = this._activeBuffer.lines.get(this._activeBuffer.ybase + y)!;
@@ -1320,13 +1320,13 @@ export class InputHandler extends Disposable implements IInputHandler {
this._restrictCursor(this._bufferService.cols); this._restrictCursor(this._bufferService.cols);
switch (params.params[0]) { switch (params.params[0]) {
case 0: case 0:
this._eraseInBufferLine(this._activeBuffer.y, this._activeBuffer.x, this._bufferService.cols); this._eraseInBufferLine(this._activeBuffer.y, this._activeBuffer.x, this._bufferService.cols, this._activeBuffer.x === 0);
break; break;
case 1: case 1:
this._eraseInBufferLine(this._activeBuffer.y, 0, this._activeBuffer.x + 1); this._eraseInBufferLine(this._activeBuffer.y, 0, this._activeBuffer.x + 1, false);
break; break;
case 2: case 2:
this._eraseInBufferLine(this._activeBuffer.y, 0, this._bufferService.cols); this._eraseInBufferLine(this._activeBuffer.y, 0, this._bufferService.cols, true);
break; break;
} }
this._dirtyRowService.markDirty(this._activeBuffer.y); this._dirtyRowService.markDirty(this._activeBuffer.y);
@@ -2264,7 +2264,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} }
// exit early if can decide color mode with semicolons // exit early if can decide color mode with semicolons
if ((accu[1] === 5 && advance + cSpace >= 2) if ((accu[1] === 5 && advance + cSpace >= 2)
|| (accu[1] === 2 && advance + cSpace >= 5)) { || (accu[1] === 2 && advance + cSpace >= 5)) {
break; break;
} }
// offset colorSpace slot for semicolon mode // offset colorSpace slot for semicolon mode
@@ -2683,7 +2683,7 @@ export class InputHandler extends Disposable implements IInputHandler {
const top = params.params[0] || 1; const top = params.params[0] || 1;
let bottom: number; let bottom: number;
if (params.length < 2 || (bottom = params.params[1]) > this._bufferService.rows || bottom === 0) { if (params.length < 2 || (bottom = params.params[1]) > this._bufferService.rows || bottom === 0) {
bottom = this._bufferService.rows; bottom = this._bufferService.rows;
} }