Fix moveToCell when target is beyond buffer

This commit is contained in:
kumaran-14
2020-02-02 23:28:24 +05:30
parent af67b72492
commit b591ccc40d
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -23,14 +23,14 @@ describe('MoveToCell', () => {
assert.equal(moveToCellSequence(4, 3, bufferService, false), '\x1b[C');
});
it('should ignore the Y value', () => {
assert.equal(moveToCellSequence(1, 1, bufferService, false), '\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D');
assert.equal(moveToCellSequence(1, 1, bufferService, false), '\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D');
assert.equal(moveToCellSequence(1, 2, bufferService, false), '\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D');
assert.equal(moveToCellSequence(1, 3, bufferService, false), '\u001b[D\u001b[D');
assert.equal(moveToCellSequence(1, 4, bufferService, false), '\u001b[C\u001b[C\u001b[C');
assert.equal(moveToCellSequence(1, 5, bufferService, false), '\u001b[C\u001b[C\u001b[C');
});
it('should use the correct character for application cursor', () => {
assert.equal(moveToCellSequence(2, 1, bufferService, false), '\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D');
assert.equal(moveToCellSequence(2, 1, bufferService, false), '\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D');
assert.equal(moveToCellSequence(2, 1, bufferService, true), '\u001bOD\u001bOD\u001bOD\u001bOD\u001bOD\u001bOD');
});
});
+1 -1
View File
@@ -37,7 +37,7 @@ export function moveToCellSequence(targetX: number, targetY: number, bufferServi
}
direction = startY > targetY ? Direction.LEFT : Direction.RIGHT;
return repeat(colsFromRowEnd(startY > targetY ? targetX : startX, bufferService), sequence(direction, applicationCursor))
+ repeat((Math.abs(wrappedRowsForRow(bufferService, startY) - wrappedRowsForRow(bufferService, targetY)) - 1 ) * bufferService.cols, sequence(direction, applicationCursor))
+ repeat((Math.abs(startY - targetY) - 1 ) * bufferService.cols, sequence(direction, applicationCursor))
+ repeat(colsFromRowBeginning(startY > targetY ? startX : targetX, bufferService), sequence(direction, applicationCursor));
}