Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update visual mode cursors:
- Removes the hardcoded cursor colors used in visual mode, now it uses
the css 'mix-blend-mode: difference' property to make the color be the
opposite of the block cursor color. This is the same
thing vscode does, except they actually calculate the value instead of
using the css property. The result however is the same color.
  • Loading branch information
berknam authored and fafrd committed Oct 7, 2021
commit cfde77121dc56a24bbf2cca00e8284bbc8a53d77
32 changes: 14 additions & 18 deletions src/configuration/decoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import { IConfiguration } from './iconfiguration';

class DecorationImpl {
private _default!: vscode.TextEditorDecorationType;
private _visualModeCursor!: vscode.TextEditorDecorationType;
private _searchHighlight!: vscode.TextEditorDecorationType;
private _easyMotionIncSearch!: vscode.TextEditorDecorationType;
private _easyMotionDimIncSearch!: vscode.TextEditorDecorationType;
Expand Down Expand Up @@ -30,15 +30,15 @@ class DecorationImpl {
});
}

public set default(value: vscode.TextEditorDecorationType) {
if (this._default) {
this._default.dispose();
public set visualModeCursor(value: vscode.TextEditorDecorationType) {
if (this._visualModeCursor) {
this._visualModeCursor.dispose();
}
this._default = value;
this._visualModeCursor = value;
}

public get default() {
return this._default;
public get visualModeCursor() {
return this._visualModeCursor;
}

public set searchHighlight(value: vscode.TextEditorDecorationType) {
Expand Down Expand Up @@ -128,18 +128,14 @@ class DecorationImpl {
}

public load(configuration: IConfiguration) {
this.default = vscode.window.createTextEditorDecorationType({
this.visualModeCursor = vscode.window.createTextEditorDecorationType({
backgroundColor: new vscode.ThemeColor('editorCursor.foreground'),
borderColor: new vscode.ThemeColor('editorCursor.foreground'),
dark: {
color: 'rgb(81,80,82)',
},
light: {
// used for light colored themes
color: 'rgb(255, 255, 255)',
},
borderStyle: 'solid',
borderWidth: '1px',
// We make the color of text 'white' -> rgb(255,255,255), because when using the mix-blend-mode
// with 'difference' it subtracts the darker color from the lightest color which means we will
// subtract the 'editorCursor.foreground' from 'white' (255,255,255) leaving us with the opposite
// color of 'editorCursor.foreground'. This is the same thing that vscode does! So the color
// should be very similar to vscode's block cursor.
color: 'white; mix-blend-mode: difference;',
});

const searchHighlightColor = configuration.searchHighlightColor
Expand Down
6 changes: 3 additions & 3 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1389,11 +1389,11 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
}
this.vimState.editor.options.cursorStyle = cursorStyle;

// cursor block
// Visual mode cursor block
const cursorRange: vscode.Range[] = [];
if (
getCursorType(this.vimState, this.currentMode) === VSCodeVimCursorType.TextDecoration &&
this.currentMode !== Mode.Insert
isVisualMode(this.currentMode)
) {
// Fake block cursor with text decoration. Unfortunately we can't have a cursor
// in the middle of a selection natively, which is what we need for Visual Mode.
Expand All @@ -1412,7 +1412,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
}
}

this.vimState.editor.setDecorations(decoration.default, cursorRange);
this.vimState.editor.setDecorations(decoration.visualModeCursor, cursorRange);

// Insert Mode virtual characters: used to temporarily show the remapping pressed keys on
// insert mode, to show the `"` character after pressing `<C-r>`, and to show `?` and the
Expand Down