Skip to content

Commit

Permalink
Address PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfn committed Feb 23, 2016
1 parent f96f38d commit 1878dbb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ModeHandler implements vscode.Disposable {

this._motion = new Motion(null);
this._modes = [
new NormalMode(this._motion),
new NormalMode(this._motion, this),
new InsertMode(this._motion),
new VisualMode(this._motion, this),
];
Expand Down
11 changes: 8 additions & 3 deletions src/mode/modeNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as vscode from 'vscode';
import {ModeName, Mode} from './mode';
import {showCmdLine} from './../cmd_line/main';
import {Motion} from './../motion/motion';
import {DeleteAction} from './../action/deleteAction';
import {ModeHandler} from './modeHandler';
import {DeleteOperator} from './../operator/delete';

export class NormalMode extends Mode {
protected keyHandler : { [key : string] : (motion : Motion) => Promise<{}>; } = {
Expand Down Expand Up @@ -37,13 +38,17 @@ export class NormalMode extends Mode {
"dd" : async () => { return vscode.commands.executeCommand("editor.action.deleteLines"); },
"dw" : async () => { return vscode.commands.executeCommand("deleteWordRight"); },
"db" : async () => { return vscode.commands.executeCommand("deleteWordLeft"); },
"x" : async (m) => { return DeleteAction.Character(m); },
"x" : async (m) => { await new DeleteOperator(this._modeHandler).run(m.position, m.position.getRight()); return {}; },
"X" : async (m) => { return vscode.commands.executeCommand("deleteLeft"); },
"esc": async () => { return vscode.commands.executeCommand("workbench.action.closeMessages"); }
};

constructor(motion : Motion) {
private _modeHandler: ModeHandler;

constructor(motion : Motion, modeHandler: ModeHandler) {
super(ModeName.Normal, motion);

this._modeHandler = modeHandler;
}

shouldBeActivated(key : string, currentMode : ModeName) : boolean {
Expand Down
6 changes: 2 additions & 4 deletions src/motion/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ export class Motion implements vscode.Disposable {
let selection = e.selections[0];

if (selection) {
const whosFirst = selection.anchor.compareTo(selection.active);

let line = whosFirst > 0 ? selection.active.line : selection.anchor.line;
let char = whosFirst > 0 ? selection.active.character : selection.anchor.character;
let line = selection.active.line;
let char = selection.active.character;

if (this.position.line !== line ||
this.position.character !== char) {
Expand Down
7 changes: 5 additions & 2 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import {NormalMode} from '../../src/mode/modeNormal';
import {ModeName} from '../../src/mode/mode';
import {Motion, MotionMode} from '../../src/motion/motion';
import {TextEditor} from '../../src/textEditor';
import {ModeHandler} from '../../src/mode/modeHandler';

suite("Mode Normal", () => {

let motion : Motion;
let modeNormal : NormalMode;
let modeHandler: ModeHandler;

setup(async () => {
await setupWorkspace();

motion = new Motion(MotionMode.Cursor);
modeNormal = new NormalMode(motion);
modeHandler = new ModeHandler();
motion = new Motion(MotionMode.Cursor);
modeNormal = new NormalMode(motion, modeHandler);
});

teardown(cleanUpWorkspace);
Expand Down

0 comments on commit 1878dbb

Please sign in to comment.