From d83e39b98a203bbb688f6006a0e35ae892040920 Mon Sep 17 00:00:00 2001 From: johnfn Date: Sun, 26 Jun 2016 18:45:11 -0400 Subject: [PATCH] Add config option for nonblinking block cursor. --- package.json | 4 ++++ src/actions/actions.ts | 3 +-- src/mode/modeHandler.ts | 35 +++++++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 27a2db12051..7b07e46d7fc 100644 --- a/package.json +++ b/package.json @@ -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." diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 9001c8d45cc..650726e43d7 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -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'; @@ -839,7 +838,7 @@ class CommandFold extends BaseCommand { keys = ["z", "c"]; public async exec(position: Position, vimState: VimState): Promise { - await vscode.commands.executeCommand("editor.fold") + await vscode.commands.executeCommand("editor.fold"); return vimState; } diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 543d75a53ed..bc48b957839 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -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 { @@ -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]; @@ -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. */ @@ -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) {