Skip to content

Commit

Permalink
Ensure diagnostics indicator stays right-most element on the left sid…
Browse files Browse the repository at this point in the history
…e of the status bar
  • Loading branch information
helgemahrt committed Dec 18, 2024
1 parent 84682ed commit 5ad3ada
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions crates/vim/src/mode_indicator.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -97,20 +98,48 @@ 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);
let pending = self
.pending_keys
.as_ref()
.unwrap_or(&current_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()
}
}
Expand Down

0 comments on commit 5ad3ada

Please sign in to comment.