diff --git a/package.json b/package.json index fb28149..b973c09 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,30 @@ "type": "string", "default": "#F8F3AB", "description": "Background color that flashes to show the range when yanking." + }, + "simpleVim.insertModeCursorStyle": { + "type": "string", + "enum": ["line", "block", "underline", "lineThin", "blockOutline", "underlineThin"], + "default": "line", + "description": "Cursor style for editor when in INSERT mode." + }, + "simpleVim.normalModeCursorStyle": { + "type": "string", + "enum": ["line", "block", "underline", "lineThin", "blockOutline", "underlineThin"], + "default": "underline", + "description": "Cursor style for editor when in NORMAL mode." + }, + "simpleVim.visualModeCursorStyle": { + "type": "string", + "enum": ["line", "block", "underline", "lineThin", "blockOutline", "underlineThin"], + "default": "lineThin", + "description": "Cursor style for editor when in VISUAL mode." + }, + "simpleVim.visualLineModeCursorStyle": { + "type": "string", + "enum": ["line", "block", "underline", "lineThin", "blockOutline", "underlineThin"], + "default": "lineThin", + "description": "Cursor style for editor when in VISUAL LINE mode." } } } diff --git a/src/modes.ts b/src/modes.ts index e3fa5c9..a54105a 100644 --- a/src/modes.ts +++ b/src/modes.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -import { Mode } from './modes_types'; +import { Mode, CursorConfigurationStyle } from './modes_types'; import { VimState } from './vim_state_types'; export function enterInsertMode(vimState: VimState): void { @@ -36,7 +36,41 @@ function setModeContext(key: string) { }); } +const configToStyleMapping: { [key in CursorConfigurationStyle]: vscode.TextEditorCursorStyle } = { + line: vscode.TextEditorCursorStyle.Line, + block: vscode.TextEditorCursorStyle.Block, + underline: vscode.TextEditorCursorStyle.Underline, + lineThin: vscode.TextEditorCursorStyle.LineThin, + blockOutline: vscode.TextEditorCursorStyle.BlockOutline, + underlineThin: vscode.TextEditorCursorStyle.UnderlineThin, +}; + +function isValidCursorConfigStyle(input: any): input is CursorConfigurationStyle { + return typeof input === 'string' && Object.keys(configToStyleMapping).indexOf(input) !== -1; +} + +function getCursorConfigStyle(mode: Mode) { + const simpleVimConfig = vscode.workspace.getConfiguration('simpleVim'); + + switch (mode) { + case Mode.Insert: + return simpleVimConfig.get('insertModeCursorStyle'); + case Mode.Normal: + return simpleVimConfig.get('normalModeCursorStyle'); + case Mode.Visual: + return simpleVimConfig.get('visualModeCursorStyle'); + case Mode.VisualLine: + return simpleVimConfig.get('visualLineModeCursorStyle'); + } +} + export function setModeCursorStyle(mode: Mode, editor: vscode.TextEditor): void { + const cursorConfigStyle = getCursorConfigStyle(mode); + if (isValidCursorConfigStyle(cursorConfigStyle)) { + editor.options.cursorStyle = configToStyleMapping[cursorConfigStyle]; + return; + } + if (mode === Mode.Insert) { editor.options.cursorStyle = vscode.TextEditorCursorStyle.Line; } else if (mode === Mode.Normal) { diff --git a/src/modes_types.ts b/src/modes_types.ts index 8c32664..d6617c8 100644 --- a/src/modes_types.ts +++ b/src/modes_types.ts @@ -1,3 +1,5 @@ +export type CursorConfigurationStyle = 'line' | 'block' | 'underline' | 'lineThin' | 'blockOutline' | 'underlineThin'; + export enum Mode { Insert, Normal,