Skip to content

Commit

Permalink
EasyMotion object is now recreated when reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Metamist committed Nov 1, 2016
1 parent d911ec0 commit d261014
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
17 changes: 11 additions & 6 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ class CommandEsc extends BaseCommand {

if (vimState.currentMode === ModeName.EasyMotionMode) {
// Escape or other termination keys were pressed, exit mode
vimState.easyMotion.exitMode();
vimState.easyMotion.clearDecorations();
vimState.currentMode = ModeName.Normal;
}

vimState.currentMode = ModeName.Normal;
Expand Down Expand Up @@ -5337,10 +5338,11 @@ abstract class BaseEasyMotionCommand extends BaseCommand {
return vimState;
}

this.processMarkers(matches, position, vimState);

// Enter the EasyMotion mode and await further keys
vimState.easyMotion.enterMode();
vimState.currentMode = ModeName.EasyMotionMode;
vimState.easyMotion = new EasyMotion();

this.processMarkers(matches, position, vimState);

return vimState;
}
Expand Down Expand Up @@ -5535,12 +5537,15 @@ class MoveEasyMotion extends BaseMovement {
if (markers.length === 1) { // Only one found, navigate to it
var marker = markers[0];

vimState.easyMotion.exitMode();
vimState.easyMotion.clearDecorations();
vimState.currentMode = ModeName.Normal;

return marker.position;
} else {
if (markers.length === 0) { // None found, exit mode
vimState.easyMotion.exitMode();
vimState.easyMotion.clearDecorations();
vimState.currentMode = ModeName.Normal;

return position;
}
}
Expand Down
31 changes: 4 additions & 27 deletions src/easymotion/easymotion.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import * as vscode from "vscode";

import { Position } from './../motion/position';
import { VimState } from './../mode/modeHandler';
import { ModeName } from './../mode/mode';
import { TextEditor } from './../textEditor';

export class EasyMotion {
private _vimState: VimState;

/**
* Refers to the accumulated keys for depth navigation
*/
Expand All @@ -18,7 +14,7 @@ export class EasyMotion {
*/
private markers: EasyMotion.Marker[];
private visibleMarkers: EasyMotion.Marker[]; // Array of currently showing markers
private decorations: any[][] = [];
private decorations: any[][];

/**
* TODO: For future motions
Expand All @@ -40,10 +36,10 @@ export class EasyMotion {
"v", "b", "n", "m", "f", "j"
];

constructor(vimState: VimState) {
this._vimState = vimState;

constructor() {
this.markers = [];
this.visibleMarkers = [];
this.decorations = [];
}

/**
Expand Down Expand Up @@ -143,25 +139,6 @@ export class EasyMotion {
return uri;
}

/**
* Enter EasyMotion mode
*/
public enterMode() {
this.accumulation = "";
this._vimState.currentMode = ModeName.EasyMotionMode;
}

/**
* Exit EasyMotion mode and clean up
*/
public exitMode() {
this._vimState.currentMode = ModeName.Normal;

this.accumulation = "";
this.clearMarkers();
this.clearDecorations();
}

/**
* Clear all decorations
*/
Expand Down
2 changes: 1 addition & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export class ModeHandler implements vscode.Disposable {
new EasyMotionMode(),
];
this.vimState.historyTracker = new HistoryTracker();
this.vimState.easyMotion = new EasyMotion(this.vimState);
this.vimState.easyMotion = new EasyMotion();

this._vimState.currentMode = ModeName.Normal;

Expand Down

0 comments on commit d261014

Please sign in to comment.