Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(modehandler-updateview): use map and remove unused context #2197

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1845,26 +1845,24 @@ export class ModeHandler implements vscode.Disposable {
}
}

let cursorRange: vscode.Range[] = [];

// Use native cursor if possible. Default to Block.
let cursorStyle = vscode.TextEditorCursorStyle.Block;
switch (this.currentMode.cursorType) {
case VSCodeVimCursorType.Line:
cursorStyle = vscode.TextEditorCursorStyle.Line;
break;
case VSCodeVimCursorType.TextDecoration:
case VSCodeVimCursorType.LineThin:
cursorStyle = vscode.TextEditorCursorStyle.LineThin;
break;
case VSCodeVimCursorType.Underline:
cursorStyle = vscode.TextEditorCursorStyle.Underline;
break;
case VSCodeVimCursorType.Native:
if (Configuration.userCursor !== undefined) {
cursorStyle = Configuration.userCursor;
}
break;
const cursorMap = new Map([
[VSCodeVimCursorType.Block, vscode.TextEditorCursorStyle.Block],
[VSCodeVimCursorType.Line, vscode.TextEditorCursorStyle.Line],
[VSCodeVimCursorType.LineThin, vscode.TextEditorCursorStyle.LineThin],
[VSCodeVimCursorType.Underline, vscode.TextEditorCursorStyle.Underline],
[VSCodeVimCursorType.TextDecoration, vscode.TextEditorCursorStyle.LineThin],
[VSCodeVimCursorType.Native, vscode.TextEditorCursorStyle.Block],
]);

// Use native cursor if possible. Otherwise translate to vscode cursor style.
let cursorStyle: vscode.TextEditorCursorStyle;
if (
this.currentMode.cursorType === VSCodeVimCursorType.Native &&
Configuration.userCursor !== undefined
) {
cursorStyle = Configuration.userCursor;
} else {
cursorStyle = cursorMap.get(this.currentMode.cursorType) as vscode.TextEditorCursorStyle;
}

const optionalCursorStyle =
Expand All @@ -1880,6 +1878,7 @@ export class ModeHandler implements vscode.Disposable {
options.cursorStyle = cursorStyle;
this._vimState.editor.options = options;

let cursorRange: vscode.Range[] = [];
if (
this.currentMode.cursorType === VSCodeVimCursorType.TextDecoration &&
this.currentMode.name !== ModeName.Insert
Expand Down Expand Up @@ -1969,14 +1968,21 @@ export class ModeHandler implements vscode.Disposable {
}
this._renderStatusBar();

vscode.commands.executeCommand('setContext', 'vim.useCtrlKeys', Configuration.useCtrlKeys);
vscode.commands.executeCommand('setContext', 'vim.overrideCopy', Configuration.overrideCopy);
vscode.commands.executeCommand(
await vscode.commands.executeCommand(
'setContext',
'vim.useCtrlKeys',
Configuration.useCtrlKeys
);
await vscode.commands.executeCommand(
'setContext',
'vim.overrideCopy',
Configuration.overrideCopy
);
await vscode.commands.executeCommand(
'setContext',
'vim.overrideCtrlC',
Configuration.overrideCopy || Configuration.useCtrlKeys
);
vscode.commands.executeCommand('setContext', 'vim.platform', process.platform);
}

private _createCurrentCommandText(): string {
Expand Down