change to max/min

This commit is contained in:
Jörg Breitbart
2019-07-09 22:30:00 +02:00
parent 9d2418ece6
commit ab25997192
2 changed files with 6 additions and 19 deletions
+2
View File
@@ -25,6 +25,8 @@ function getCursor(term: TestTerminal): number[] {
describe('InputHandler', () => {
describe('save and restore cursor', () => {
const terminal = new MockInputHandlingTerminal();
terminal.cols = 80;
terminal.rows = 30;
terminal.buffer.x = 1;
terminal.buffer.y = 2;
terminal.buffer.ybase = 0;
+4 -19
View File
@@ -584,25 +584,10 @@ export class InputHandler extends Disposable implements IInputHandler {
* Restrict cursor to viewport size / scroll margin (origin mode).
*/
private _restrictCursor(): void {
// cols
if (this._terminal.buffer.x < 0) {
this._terminal.buffer.x = 0;
} else if (this._terminal.buffer.x >= this._terminal.cols) {
this._terminal.buffer.x = this._terminal.cols - 1;
}
// rows
if (this._terminal.buffer.y < 0) {
this._terminal.buffer.y = 0;
} else if (this._terminal.buffer.y >= this._terminal.rows) {
this._terminal.buffer.y = this._terminal.rows - 1;
}
if (this._terminal.originMode) {
if (this._terminal.buffer.y < this._terminal.buffer.scrollTop) {
this._terminal.buffer.y = this._terminal.buffer.scrollTop;
} else if (this._terminal.buffer.y > this._terminal.buffer.scrollBottom) {
this._terminal.buffer.y = this._terminal.buffer.scrollBottom;
}
}
this._terminal.buffer.x = Math.min(this._terminal.cols - 1, Math.max(0, this._terminal.buffer.x));
this._terminal.buffer.y = this._terminal.originMode
? Math.min(this._terminal.buffer.scrollBottom, Math.max(this._terminal.buffer.scrollTop, this._terminal.buffer.y))
: Math.min(this._terminal.rows - 1, Math.max(0, this._terminal.buffer.y));
}
/**