Skip to content

Commit

Permalink
fix: validate cursor position on setters
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon committed Feb 2, 2019
1 parent 4d63c47 commit 8ff4bad
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/state/vimState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down

0 comments on commit 8ff4bad

Please sign in to comment.