Skip to content

Commit ffe513d

Browse files
authored
statusline: dynamic padding for unfocused mode (#14440)
1 parent d015eff commit ffe513d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

helix-term/src/ui/statusline.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::borrow::Cow;
2-
31
use helix_core::indent::IndentStyle;
4-
use helix_core::{coords_at_pos, encoding, Position};
2+
use helix_core::{coords_at_pos, encoding, unicode::width::UnicodeWidthStr, Position};
53
use helix_lsp::lsp::DiagnosticSeverity;
64
use helix_view::document::DEFAULT_LANGUAGE_NAME;
75
use helix_view::{
@@ -169,18 +167,16 @@ where
169167
let visible = context.focused;
170168
let config = context.editor.config();
171169
let modenames = &config.statusline.mode;
170+
let mode_str = match context.editor.mode() {
171+
Mode::Insert => &modenames.insert,
172+
Mode::Select => &modenames.select,
173+
Mode::Normal => &modenames.normal,
174+
};
172175
let content = if visible {
173-
Cow::Owned(format!(
174-
" {} ",
175-
match context.editor.mode() {
176-
Mode::Insert => &modenames.insert,
177-
Mode::Select => &modenames.select,
178-
Mode::Normal => &modenames.normal,
179-
}
180-
))
176+
format!(" {mode_str} ")
181177
} else {
182178
// If not focused, explicitly leave an empty space instead of returning None.
183-
Cow::Borrowed(" ")
179+
" ".repeat(mode_str.width() + 2)
184180
};
185181
let style = if visible && config.color_modes {
186182
match context.editor.mode() {

0 commit comments

Comments
 (0)