From 5fc9d3c392a2df1e0e60a528e08de9a57f300842 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 1 Sep 2024 02:52:21 -0700 Subject: [PATCH 1/2] feat: directly color the vim mode status bar item --- package.json | 110 +++++++++++++++++++++++++++++++++++++++++++++++ src/statusBar.ts | 23 +++++++--- 2 files changed, 128 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 20b9c8f2894..0bd6852c5ed 100644 --- a/package.json +++ b/package.json @@ -1152,6 +1152,116 @@ } } }, + "colors": [ + { + "id": "statusBarItem.vimMode.Normal", + "description": "Vim status bar color for normal mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.Insert", + "description": "Vim status bar color for insert mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.Visual", + "description": "Vim status bar color for visual mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.VisualBlock", + "description": "Vim status bar color for visual block mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.VisualLine", + "description": "Vim status bar color for visual line mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.Replace", + "description": "Vim status bar color for replace mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.EasyMotionMode", + "description": "Vim status bar color for easy motion mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.EasyMotionInputMode", + "description": "Vim status bar color for easy motion input mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.SurroundInputMode", + "description": "Vim status bar color for surround input mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.Disabled", + "description": "Vim status bar color for disabled mode.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.SearchInProgressMode", + "description": "Vim status bar color for when a search is in progress.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + }, + { + "id": "statusBarItem.vimMode.CommandlineInProgress", + "description": "Vim status bar color for when entering a command.", + "defaults": { + "dark": "statusBar.foreground", + "light": "statusBar.foreground", + "highContrast": "statusBar.foreground" + } + } + ], "languages": [ { "id": "Vimscript", diff --git a/src/statusBar.ts b/src/statusBar.ts index 65253f2754e..d9d15253044 100644 --- a/src/statusBar.ts +++ b/src/statusBar.ts @@ -70,11 +70,7 @@ class StatusBarImpl implements vscode.Disposable { } // StatusBar color - const shouldUpdateColor = - configuration.statusBarColorControl && vimState.currentMode !== this.previousMode; - if (shouldUpdateColor) { - this.updateColor(vimState.currentMode); - } + this.updateColor(vimState.currentMode); this.previousMode = vimState.currentMode; this.showingDefaultMessage = false; @@ -123,6 +119,23 @@ class StatusBarImpl implements vscode.Disposable { } private updateColor(mode: Mode) { + // original color update method - applies to the whole line by modifying the user's settings + if (configuration.statusBarColorControl && mode !== this.previousMode) { + this.updateWholeStatusBarColor(mode); + } + + // narrow color update method - applies to the Vim status bar items based on color settings + this.updateVimStatusItemColor(mode); + } + + private updateVimStatusItemColor(mode: Mode) { + const modeName = Mode[mode]; + const foregroundColor = new vscode.ThemeColor(`statusBarItem.vimMode.${modeName}`); + this.statusBarItem.color = foregroundColor; + this.recordedStateStatusBarItem.color = foregroundColor; + } + + private updateWholeStatusBarColor(mode: Mode) { let foreground: string | undefined; let background: string | undefined; From caec000915e01e872f7e0b319c8b7f8e754441b0 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 1 Sep 2024 03:17:46 -0700 Subject: [PATCH 2/2] dev: improved function naming consistency --- src/statusBar.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/statusBar.ts b/src/statusBar.ts index d9d15253044..45787295a3a 100644 --- a/src/statusBar.ts +++ b/src/statusBar.ts @@ -125,10 +125,10 @@ class StatusBarImpl implements vscode.Disposable { } // narrow color update method - applies to the Vim status bar items based on color settings - this.updateVimStatusItemColor(mode); + this.updateVimStatusBarItemColor(mode); } - private updateVimStatusItemColor(mode: Mode) { + private updateVimStatusBarItemColor(mode: Mode) { const modeName = Mode[mode]; const foregroundColor = new vscode.ThemeColor(`statusBarItem.vimMode.${modeName}`); this.statusBarItem.color = foregroundColor;