From 73420a222101351a3761f7d79fc9ea120c4e5258 Mon Sep 17 00:00:00 2001 From: xconverge Date: Thu, 5 Oct 2017 18:30:09 -0700 Subject: [PATCH] Fixes #2050 --- README.md | 13 +++++++++++ package.json | 4 ++++ src/configuration/configuration.ts | 37 +++++++++++++++++++++--------- src/mode/modeHandler.ts | 13 ++++++++++- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a1281e711..3ee78bdea 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,19 @@ We have removed this option, due to it making VSCodeVim's performance suffer imm * In visual mode, start a search with * or # using the current selection * Type: Boolean (Default: `false`) +#### `"vim.cursorStylePerMode"` +* Configure a specific cursor style per mode, any modes omitted will use default cursor type +* Modes available are normal, insert, replace, visual, visualline, and visualblock +* Cursors available are line, block, underline, line-thin, block-outline, and underline-thin + +``` + "vim.cursorStylePerMode" : { + "normal": "underline", + "insert": "line-thin", + "replace": "block-outline" + } +``` + ### Neovim Integration We now have neovim integration for Ex-commands. If you want to take advantage of this integration, set `"vim.enableNeovim"` to `true`, and set your `"vim.neovimPath"`. If you don't have neovim installed, [install neovim here](https://github.com/neovim/neovim/wiki/Installing-Neovim). If you don't want to install neovim, all of the old functionality should still work as is (we would really suggest neovim installing though. The new Ex support is super cool, and we'd like to integrate neovim more in the future). diff --git a/package.json b/package.json index 009cbeb9d..af2d4096c 100644 --- a/package.json +++ b/package.json @@ -542,6 +542,10 @@ "type": "boolean", "description": "Automatically apply the global flag, /g, to substitute commands. When set to true, use /g to mean only first match should be replaced.", "default": "false" + }, + "vim.cursorStylePerMode": { + "type": "object", + "description": "Customize cursor style per mode" } } } diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index ac4731abe..7c7cb4972 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -12,13 +12,13 @@ export interface IHandleKeys { [key: string]: boolean; } -export interface IStatusBarColors { - normal: string; - insert: string; - visual: string; - visualline: string; - visualblock: string; - replace: string; +export interface IModeSpecificStrings { + normal: string | undefined; + insert: string | undefined; + visual: string | undefined; + visualline: string | undefined; + visualblock: string | undefined; + replace: string | undefined; } /** @@ -79,6 +79,9 @@ class ConfigurationClass { .getConfiguration() .get('editor.cursorStyle') as string; this.userCursor = this.cursorStyleFromString(cursorStyleString); + if (this.userCursor === undefined) { + this.userCursor = this.cursorStyleFromString('line'); + } // Get configuration setting for handled keys, this allows user to disable // certain key comboinations @@ -113,7 +116,7 @@ class ConfigurationClass { } } - private cursorStyleFromString(cursorStyle: string): vscode.TextEditorCursorStyle { + public cursorStyleFromString(cursorStyle: string): vscode.TextEditorCursorStyle | undefined { const cursorType = { line: vscode.TextEditorCursorStyle.Line, block: vscode.TextEditorCursorStyle.Block, @@ -126,7 +129,7 @@ class ConfigurationClass { if (cursorType[cursorStyle] !== undefined) { return cursorType[cursorStyle]; } else { - return vscode.TextEditorCursorStyle.Line; + return undefined; } } @@ -233,7 +236,7 @@ class ConfigurationClass { /** * Status bar colors to change to based on mode */ - statusBarColors: IStatusBarColors = { + statusBarColors: IModeSpecificStrings = { normal: '#005f5f', insert: '#5f0000', visual: '#5f00af', @@ -256,7 +259,7 @@ class ConfigurationClass { /** * Type of cursor user is using native to vscode */ - userCursor: number; + userCursor: number | undefined; /** * Use spaces when the user presses tab? @@ -309,6 +312,18 @@ class ConfigurationClass { * Automatically apply the /g flag to substitute commands. */ substituteGlobalFlag = false; + + /** + * Cursor style to set based on mode + */ + cursorStylePerMode: IModeSpecificStrings = { + normal: undefined, + insert: undefined, + visual: undefined, + visualline: undefined, + visualblock: undefined, + replace: undefined, + }; } function overlapSetting(args: { diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 6fce5450f..be9c6981b 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -1845,10 +1845,21 @@ export class ModeHandler implements vscode.Disposable { cursorStyle = vscode.TextEditorCursorStyle.Underline; break; case VSCodeVimCursorType.Native: - cursorStyle = Configuration.userCursor; + if (Configuration.userCursor !== undefined) { + cursorStyle = Configuration.userCursor; + } break; } + const optionalCursorStyle = + Configuration.cursorStylePerMode[this._vimState.currentModeName().toLowerCase()]; + if (optionalCursorStyle !== undefined) { + const cursorStyleNum = Configuration.cursorStyleFromString(optionalCursorStyle); + if (cursorStyleNum !== undefined) { + cursorStyle = cursorStyleNum; + } + } + let options = this._vimState.editor.options; options.cursorStyle = cursorStyle; this._vimState.editor.options = options;