Skip to content

Commit

Permalink
Merge pull request #53 from adriaanp/words
Browse files Browse the repository at this point in the history
Add word motion and db
  • Loading branch information
jpoon committed Nov 29, 2015
2 parents 263a5ef + 6cafd08 commit cc7decc
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/mode/modeNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export default class CommandMode extends Mode {
"j" : () => { vscode.commands.executeCommand("cursorDown"); },
"k" : () => { vscode.commands.executeCommand("cursorUp"); },
"l" : () => { vscode.commands.executeCommand("cursorRight"); },
"w" : () => { vscode.commands.executeCommand("cursorWordRight"); },
"b" : () => { vscode.commands.executeCommand("cursorWordLeft"); },
">>" : () => { vscode.commands.executeCommand("editor.action.indentLines"); },
"<<" : () => { vscode.commands.executeCommand("editor.action.outdentLines"); },
"dd" : () => { vscode.commands.executeCommand("editor.action.deleteLines"); },
"dw" : () => { vscode.commands.executeCommand("deleteWordRight"); },
"db" : () => { vscode.commands.executeCommand("deleteWordLeft"); },
"esc": () => { vscode.commands.executeCommand("workbench.action.closeMessages"); }
};
}
Expand All @@ -40,15 +43,22 @@ export default class CommandMode extends Mode {
this.keyHistory.push(key);

let keyHandled = false;
for (let window = 1; window <= this.keyHistory.length; window++) {
var keysPressed = _.takeRight(this.keyHistory, window).join('');
if (this.keyHandler[keysPressed] !== undefined) {
keyHandled = true;
this.keyHandler[keysPressed]();
break;

let keysPressed = this.keyHistory.join('');
if (this.keyHandler[keysPressed] !== undefined) {
keyHandled = true;
this.keyHandler[keysPressed]();
} else {
for (let window = 1; window <= this.keyHistory.length; window++) {
keysPressed = _.takeRight(this.keyHistory, window).join('');
if (this.keyHandler[keysPressed] !== undefined) {
keyHandled = true;
this.keyHandler[keysPressed]();
break;
}
}
}

if (keyHandled) {
this.keyHistory = [];
}
Expand Down

0 comments on commit cc7decc

Please sign in to comment.