From 8ff4bad127534f71b7c5abf58039a2b66f790d55 Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Fri, 1 Feb 2019 22:08:16 -0800 Subject: [PATCH] fix: validate cursor position on setters --- src/state/vimState.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/state/vimState.ts b/src/state/vimState.ts index 4ecb25dac5a..62c0bdfd80c 100644 --- a/src/state/vimState.ts +++ b/src/state/vimState.ts @@ -120,26 +120,29 @@ export class VimState implements vscode.Disposable { public globalState = globalState; /** - * The position the cursor will be when this action finishes. + * The cursor position (start, stop) when this action finishes. */ + public get cursorStartPosition(): Position { + return this.cursors[0].start; + } + public set cursorStartPosition(value: Position) { + if (!value.isValid(this.editor)) { + this.logger.warn(`invalid cursor start position. ${value.toString()}.`); + } + this.cursors[0] = this.cursors[0].withNewStart(value); + } + public get cursorStopPosition(): Position { return this.cursors[0].stop; } public set cursorStopPosition(value: Position) { + if (!value.isValid(this.editor)) { + this.logger.warn(`invalid cursor stop position. ${value.toString()}.`); + } this.cursors[0] = this.cursors[0].withNewStop(value); } - /** - * The effective starting position of the movement, used along with cursorPosition to determine - * the range over which to run an Operator. May rarely be different than where the cursor - * actually starts e.g. if you use the "aw" text motion in the middle of a word. - */ - public get cursorStartPosition(): Position { - return this.cursors[0].start; - } - public set cursorStartPosition(value: Position) { - this.cursors[0] = this.cursors[0].withNewStart(value); - } + /** * The position of every cursor. @@ -149,14 +152,14 @@ export class VimState implements vscode.Disposable { public get cursors(): Range[] { return this._cursors; } - public set cursors(cursors: Range[]) { - for (const cursor of cursors) { + public set cursors(value: Range[]) { + for (const cursor of value) { if (!cursor.isValid(this.editor)) { this.logger.warn(`invalid cursor position. ${cursor.toString()}.`); } } - this._cursors = cursors; + this._cursors = value; this.isMultiCursor = this._cursors.length > 1; }