Skip to content

Commit

Permalink
Set correct cursor and selection after code format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jul 19, 2016
1 parent 2a8b46e commit f3c1ad0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@ class CommandFormatCode extends BaseCommand {

public async exec(position: Position, vimState: VimState): Promise<VimState> {
await vscode.commands.executeCommand("editor.action.format");

let selection = vscode.window.activeTextEditor.selection;
let line = selection.start.line;

if (selection.start.isAfter(selection.end)) {
line = selection.end.line;
}

let newCursorPosition = new Position(line, 0);
vimState.cursorPosition = newCursorPosition;
vimState.cursorStartPosition = newCursorPosition;
vscode.window.activeTextEditor.selection = new vscode.Selection(newCursorPosition, newCursorPosition);
vimState.currentMode = ModeName.Normal;
return vimState;
}
Expand Down

0 comments on commit f3c1ad0

Please sign in to comment.