From ab25997192422dcd5ed0b0d5369818fced222d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 9 Jul 2019 22:30:00 +0200 Subject: [PATCH] change to max/min --- src/InputHandler.test.ts | 2 ++ src/InputHandler.ts | 23 ++++------------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index 6d4a3ca8a..d5f0ecd6c 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -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; diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 5e34c8b63..150ed8bba 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -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)); } /**