From 3846fe0a7db2398b7c40f4116b176d648be13dd2 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 25 May 2017 09:55:08 -0700 Subject: [PATCH] Add null checks to fix trim related crash --- src/SelectionManager.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 5e196f7b..8648c587 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -131,11 +131,15 @@ export class SelectionManager extends EventEmitter { */ private _onTrim(amount: number) { // Adjust the selection position based on the trimmed amount. - this._selectionStart[0] -= amount; - this._selectionEnd[0] -= amount; + if (this._selectionStart) { + this._selectionStart[0] -= amount; + } + if (this._selectionEnd) { + this._selectionEnd[0] -= amount; + } // The selection has moved off the buffer, clear it. - if (this._selectionEnd[0] < 0) { + if (this._selectionEnd && this._selectionEnd[0] < 0) { this._selectionStart = null; this._selectionEnd = null; this.refresh(); @@ -143,7 +147,7 @@ export class SelectionManager extends EventEmitter { } // If the selection start is trimmed, ensure the start column is 0. - if (this._selectionStart[0] < 0) { + if (this._selectionStart && this._selectionStart[0] < 0) { this._selectionStart[1] = 0; } }