Skip to content

Commit

Permalink
Merge pull request #361 from VSCodeVim/nonblinking-cursor
Browse files Browse the repository at this point in the history
Add config option for nonblinking block cursor.
  • Loading branch information
johnfn committed Jun 26, 2016
2 parents 34e38dc + d83e39b commit d252b63
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
"type": "object",
"description": "Keybinding overrides to use for insert mode."
},
"vim.useSolidBlockCursor": {
"type": "boolean",
"description": "Use a non blinking block cursor."
},
"vim.visualModeKeyBindings": {
"type": "object",
"description": "Keybinding overrides to use for visual mode."
Expand Down
3 changes: 1 addition & 2 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { VimSpecialCommands, VimState, SearchState } from './../mode/modeHandler';
import { showCmdLine } from '../../src/cmd_line/main';
import { ModeName } from './../mode/mode';
import { TextEditor } from './../textEditor';
import { Register, RegisterMode } from './../register/register';
Expand Down Expand Up @@ -839,7 +838,7 @@ class CommandFold extends BaseCommand {
keys = ["z", "c"];

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

return vimState;
}
Expand Down
35 changes: 29 additions & 6 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export class VimState {
* by us or by a mouse action.
*/
public whatILastSetTheSelectionTo: vscode.Selection;

public settings = new VimSettings();
}

export class VimSettings {
useSolidBlockCursor = false;
}

export class SearchState {
Expand Down Expand Up @@ -360,6 +366,8 @@ export class ModeHandler implements vscode.Disposable {
this._vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
}

this.loadSettings();

// Handle scenarios where mouse used to change current position.
vscode.window.onDidChangeTextEditorSelection(async (e) => {
let selection = e.selections[0];
Expand Down Expand Up @@ -422,6 +430,11 @@ export class ModeHandler implements vscode.Disposable {
});
}

private loadSettings(): void {
this._vimState.settings.useSolidBlockCursor = vscode.workspace.getConfiguration("vim")
.get("useSolidBlockCursor", false);
}

/**
* The active mode.
*/
Expand Down Expand Up @@ -738,13 +751,23 @@ export class ModeHandler implements vscode.Disposable {

// Draw block cursor.

// Use native block cursor if possible.
const options = vscode.window.activeTextEditor.options;
if (vimState.settings.useSolidBlockCursor) {
if (this.currentMode.name !== ModeName.Insert) {
rangesToDraw.push(new vscode.Range(
vimState.cursorPosition,
vimState.cursorPosition.getRight()
));
}
} else {
// Use native block cursor if possible.

const options = vscode.window.activeTextEditor.options;

options.cursorStyle = this.currentMode.cursorType === VSCodeVimCursorType.Native &&
this.currentMode.name !== ModeName.Insert ?
vscode.TextEditorCursorStyle.Block : vscode.TextEditorCursorStyle.Line;
vscode.window.activeTextEditor.options = options;
options.cursorStyle = this.currentMode.cursorType === VSCodeVimCursorType.Native &&
this.currentMode.name !== ModeName.Insert ?
vscode.TextEditorCursorStyle.Block : vscode.TextEditorCursorStyle.Line;
vscode.window.activeTextEditor.options = options;
}

if (this.currentMode.cursorType === VSCodeVimCursorType.TextDecoration &&
this.currentMode.name !== ModeName.Insert) {
Expand Down

0 comments on commit d252b63

Please sign in to comment.