Skip to content

Commit

Permalink
Merge pull request #65 from kimitake/support-x
Browse files Browse the repository at this point in the history
support x command
  • Loading branch information
jpoon committed Dec 1, 2015
2 parents 88343c7 + af95f5e commit 46df0b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,15 @@ export default class Cursor {
private static isLastLine(line: number): boolean {
return (vscode.window.activeTextEditor.document.lineCount - 1) === line;
}

static checkLineEnd() : void {
let pos = this.currentPosition();
const lineLength = TextEditor.ReadLine(pos.line).length;
if (pos.character === 0 || lineLength === 0) {
return;
} else if (pos.character >= lineLength) {
this.move(pos.translate(0, -1));
}
}
}

13 changes: 12 additions & 1 deletion src/mode/modeNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from 'vscode';
import {ModeName, Mode} from './mode';
import {showCmdLine} from './../cmd_line/main';
import Cursor from './../cursor';
import TextEditor from './../textEditor';

export default class CommandMode extends Mode {
private keyHandler : { [key : string] : () => void; } = {};
Expand All @@ -25,7 +26,8 @@ export default class CommandMode extends Mode {
"dd" : () => { vscode.commands.executeCommand("editor.action.deleteLines"); },
"dw" : () => { vscode.commands.executeCommand("deleteWordRight"); },
"db" : () => { vscode.commands.executeCommand("deleteWordLeft"); },
"esc": () => { vscode.commands.executeCommand("workbench.action.closeMessages"); }
"esc": () => { vscode.commands.executeCommand("workbench.action.closeMessages"); },
"x" : () => { this.CommandDelete(1); }
};
}

Expand Down Expand Up @@ -58,4 +60,13 @@ export default class CommandMode extends Mode {
this.keyHistory = [];
}
}

private CommandDelete(n: number) : void {
var pos : vscode.Position = Cursor.currentPosition();
var end : vscode.Position = pos.translate(0, n);
var range : vscode.Range = new vscode.Range(pos, end);
TextEditor.Delete(range).then(function() {
Cursor.checkLineEnd();
});
}
}

0 comments on commit 46df0b6

Please sign in to comment.