From 5ad3ada7bb7a9c8c174de404d1e1696a733d6637 Mon Sep 17 00:00:00 2001 From: Helge Mahrt <5497139+helgemahrt@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:12:13 +0100 Subject: [PATCH] Ensure diagnostics indicator stays right-most element on the left side of the status bar --- crates/vim/src/mode_indicator.rs | 45 ++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/crates/vim/src/mode_indicator.rs b/crates/vim/src/mode_indicator.rs index 8b608fdfe34d14..b9b13e4d34806c 100644 --- a/crates/vim/src/mode_indicator.rs +++ b/crates/vim/src/mode_indicator.rs @@ -1,8 +1,9 @@ -use gpui::{div, Element, Render, Subscription, View, ViewContext, WeakView}; +use gpui::{div, Element, Hsla, Render, Subscription, View, ViewContext, WeakView}; use itertools::Itertools; +use theme::SystemColors; use workspace::{item::ItemHandle, ui::prelude::*, StatusItemView}; -use crate::{Vim, VimEvent, VimGlobals}; +use crate::{state::Mode, Vim, VimEvent, VimGlobals}; /// The ModeIndicator displays the current mode in the status bar. pub struct ModeIndicator { @@ -97,10 +98,32 @@ impl Render for ModeIndicator { }; let vim_readable = vim.read(cx); - let mode = if vim_readable.temp_mode { - format!("(insert) {}", vim_readable.mode) + let (mode, color, background) = if vim_readable.temp_mode { + ( + format!("(insert) {}", vim_readable.mode), + cx.theme().colors().vim_mode_indicator_insert_text, + cx.theme().colors().vim_mode_indicator_insert_background, + ) } else { - vim_readable.mode.to_string() + let (color, background) = match vim_readable.mode { + Mode::Normal | Mode::HelixNormal => ( + cx.theme().colors().vim_mode_indicator_normal_text, + cx.theme().colors().vim_mode_indicator_normal_background, + ), + Mode::Insert => ( + cx.theme().colors().vim_mode_indicator_insert_text, + cx.theme().colors().vim_mode_indicator_insert_background, + ), + Mode::Visual | Mode::VisualLine | Mode::VisualBlock => ( + cx.theme().colors().vim_mode_indicator_visual_text, + cx.theme().colors().vim_mode_indicator_visual_background, + ), + Mode::Replace => ( + cx.theme().colors().vim_mode_indicator_replace_text, + cx.theme().colors().vim_mode_indicator_replace_background, + ), + }; + (vim_readable.mode.to_string(), color, background) }; let current_operators_description = self.current_operators_description(vim.clone(), cx); @@ -108,9 +131,15 @@ impl Render for ModeIndicator { .pending_keys .as_ref() .unwrap_or(¤t_operators_description); - Label::new(format!("{} -- {} --", pending, mode)) - .size(LabelSize::Small) - .line_height_style(LineHeightStyle::UiLabel) + div() + .bg(Hsla::red()) + .child( + Label::new(format!("{} -- {} --", pending, mode)) + .size(LabelSize::Small) + .color(Color::Custom(color)) + // .background(Color::Custom(background)) + .line_height_style(LineHeightStyle::UiLabel), + ) .into_any_element() } }