Skip to content

Commit

Permalink
Merge pull request #2054 from xconverge/customize-cursor-styles
Browse files Browse the repository at this point in the history
Fixes #2050 Allow custom cursor styles per mode
  • Loading branch information
xconverge authored Oct 7, 2017
2 parents 09ea885 + 73420a2 commit 8da76ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
37 changes: 26 additions & 11 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -126,7 +129,7 @@ class ConfigurationClass {
if (cursorType[cursorStyle] !== undefined) {
return cursorType[cursorStyle];
} else {
return vscode.TextEditorCursorStyle.Line;
return undefined;
}
}

Expand Down Expand Up @@ -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',
Expand All @@ -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?
Expand Down Expand Up @@ -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: {
Expand Down
13 changes: 12 additions & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8da76ef

Please sign in to comment.