From b5c7ca49d2168328809324e0d4b27b05ea0d1ca7 Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 29 Apr 2017 06:48:00 -0400 Subject: [PATCH 1/4] Fixes #1532 --- src/mode/modeHandler.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 4b763e337f5..a8361a83ee4 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -39,6 +39,7 @@ import { PairMatcher } from './../matching/matcher'; import { Globals } from '../../src/globals'; import { ReplaceState } from './../state/replaceState'; import { GlobalState } from './../state/globalState'; +import { waitForCursorUpdatesToHappen } from './../util' export class ViewChange { public command: string; @@ -515,7 +516,6 @@ export class ModeHandler implements vscode.Disposable { ]; this.vimState.historyTracker = new HistoryTracker(this.vimState); this.vimState.easyMotion = new EasyMotion(); - if (Configuration.startInInsertMode) { this._vimState.currentMode = ModeName.Insert; } else { @@ -534,13 +534,15 @@ export class ModeHandler implements vscode.Disposable { // position to the position that VSC set it to. // This also makes things like gd work. - if (this._vimState.editor) { - this._vimState.cursorStartPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start); - this._vimState.cursorPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start); - this._vimState.desiredColumn = this._vimState.cursorPosition.character; + this.updateView(this.vimState, {drawSelection: false, revealRange: false}).then(() => { + if (this._vimState.editor) { + this._vimState.cursorStartPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start); + this._vimState.cursorPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start); + this._vimState.desiredColumn = this._vimState.cursorPosition.character; - this._vimState.whatILastSetTheSelectionTo = this._vimState.editor.selection; - } + this._vimState.whatILastSetTheSelectionTo = this._vimState.editor.selection; + } + }); // Handle scenarios where mouse used to change current position. const disposer = vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => { From 162620e20dbab3d1a5a70b24a0f577ba5d3464ab Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 29 Apr 2017 06:53:18 -0400 Subject: [PATCH 2/4] Cleaned up unnecessary things --- src/mode/modeHandler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 2dd8e8c8830..29e4ffee284 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -39,7 +39,6 @@ import { PairMatcher } from './../matching/matcher'; import { Globals } from '../../src/globals'; import { ReplaceState } from './../state/replaceState'; import { GlobalState } from './../state/globalState'; -import { waitForCursorUpdatesToHappen } from './../util' export class ViewChange { public command: string; From cb091d28e4c33488424ccbf3e689e120b21804be Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 29 Apr 2017 07:40:07 -0400 Subject: [PATCH 3/4] changed updateView to something more reasonable --- src/mode/modeHandler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 29e4ffee284..b9e9755234b 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -533,7 +533,7 @@ export class ModeHandler implements vscode.Disposable { // position to the position that VSC set it to. // This also makes things like gd work. - this.updateView(this.vimState, {drawSelection: false, revealRange: false}).then(() => { + setTimeout(() => { if (this._vimState.editor) { this._vimState.cursorStartPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start); this._vimState.cursorPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start); @@ -541,7 +541,7 @@ export class ModeHandler implements vscode.Disposable { this._vimState.whatILastSetTheSelectionTo = this._vimState.editor.selection; } - }); + }, 0); // Handle scenarios where mouse used to change current position. const disposer = vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => { From 020c58a0daf59a1debfbf7c8adcd03dad8e677f5 Mon Sep 17 00:00:00 2001 From: Horace He Date: Sat, 29 Apr 2017 15:08:43 -0400 Subject: [PATCH 4/4] Added short explanation for fix --- src/mode/modeHandler.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index b9e9755234b..838e7b30dc7 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -533,6 +533,8 @@ export class ModeHandler implements vscode.Disposable { // position to the position that VSC set it to. // This also makes things like gd work. + // For whatever reason, the editor positions aren't updated until after the + // stack clears, which is why this setTimeout is necessary setTimeout(() => { if (this._vimState.editor) { this._vimState.cursorStartPosition = Position.FromVSCodePosition(this._vimState.editor.selection.start);