From 3b20229fa1ca6962cb421dad0db313626fdc3457 Mon Sep 17 00:00:00 2001 From: R Aadarsh Date: Tue, 26 Aug 2025 23:54:57 +0530 Subject: [PATCH] feat: Make the encoding indicator appear only when an editor is open. feat: Enable the user to choose whether or not the encoding indicator should be displayed by enabling or disabling `encoding_indicator` in `settings.json` --- Cargo.lock | 1 + assets/settings/default.json | 4 +++- crates/editor/src/editor_settings.rs | 9 +++++++++ crates/encodings/Cargo.toml | 13 +++++++------ crates/encodings/src/lib.rs | 13 ++++++++++++- docs/src/configuring-zed.md | 3 ++- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83a14b5867..d6ce0130ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5282,6 +5282,7 @@ dependencies = [ "gpui", "language", "picker", + "settings", "ui", "util", "workspace", diff --git a/assets/settings/default.json b/assets/settings/default.json index 804198090f..399eb1892f 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -1258,7 +1258,9 @@ // Whether to show the active language button in the status bar. "active_language_button": true, // Whether to show the cursor position button in the status bar. - "cursor_position_button": true + "cursor_position_button": true, + // Whether to show the encoding indicator in the status bar. + "encoding_indicator": true }, // Settings specific to the terminal "terminal": { diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 1d7e04cae0..29a5dd43d4 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -136,6 +136,11 @@ pub struct StatusBar { /// /// Default: true pub cursor_position_button: bool, + + /// Whether to show the encoding indicator in the status bar. + /// + /// Default: true + pub encoding_indicator: bool, } #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] @@ -593,6 +598,10 @@ pub struct StatusBarContent { /// /// Default: true pub cursor_position_button: Option, + /// Whether to show the encoding indicator in the status bar. + /// + /// Default: true + pub encoding_indicator: Option, } // Toolbar related settings diff --git a/crates/encodings/Cargo.toml b/crates/encodings/Cargo.toml index dd47679500..a4c2b959e8 100644 --- a/crates/encodings/Cargo.toml +++ b/crates/encodings/Cargo.toml @@ -6,15 +6,16 @@ edition.workspace = true [dependencies] anyhow.workspace = true -ui.workspace = true -workspace.workspace = true -gpui.workspace = true -picker.workspace = true -util.workspace = true -fuzzy.workspace = true editor.workspace = true encoding.workspace = true +fuzzy.workspace = true +gpui.workspace = true language.workspace = true +picker.workspace = true +settings.workspace = true +ui.workspace = true +util.workspace = true +workspace.workspace = true [lints] workspace = true diff --git a/crates/encodings/src/lib.rs b/crates/encodings/src/lib.rs index 91c1e8799a..9715a48d94 100644 --- a/crates/encodings/src/lib.rs +++ b/crates/encodings/src/lib.rs @@ -1,5 +1,5 @@ ///! A crate for handling file encodings in the text editor. -use editor::Editor; +use editor::{Editor, EditorSettings}; use encoding::Encoding; use encoding::all::{ BIG5_2003, EUC_JP, GB18030, GBK, HZ, IBM866, ISO_2022_JP, ISO_8859_1, ISO_8859_2, ISO_8859_3, @@ -9,6 +9,7 @@ use encoding::all::{ WINDOWS_1253, WINDOWS_1254, WINDOWS_1255, WINDOWS_1256, WINDOWS_1257, WINDOWS_1258, }; use gpui::{ClickEvent, Entity, Subscription, WeakEntity}; +use settings::Settings; use ui::{Button, ButtonCommon, Context, LabelSize, Render, Tooltip, Window, div}; use ui::{Clickable, ParentElement}; use workspace::{ItemHandle, StatusItemView, Workspace}; @@ -20,6 +21,7 @@ pub struct EncodingIndicator { pub encoding: Option<&'static dyn Encoding>, pub workspace: WeakEntity, observe: Option, // Subscription to observe changes in the active editor + show: bool, } pub mod selectors; @@ -28,6 +30,12 @@ impl Render for EncodingIndicator { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl ui::IntoElement { let status_element = div(); + if (EditorSettings::get_global(cx).status_bar.encoding_indicator == false) + || (self.show == false) + { + return status_element; + } + status_element.child( Button::new("encoding", encoding_name(self.encoding.unwrap_or(UTF_8))) .label_size(LabelSize::Small) @@ -54,6 +62,7 @@ impl EncodingIndicator { encoding, workspace, observe, + show: true, } } @@ -84,10 +93,12 @@ impl StatusItemView for EncodingIndicator { Some(editor) => { self.observe = Some(cx.observe_in(&editor, window, Self::update)); self.update(editor, window, cx); + self.show = true; } None => { self.encoding = None; self.observe = None; + self.show = false; } } } diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index a8a4689689..a7ec556ffe 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -1278,7 +1278,8 @@ Each option controls displaying of a particular toolbar element. If all elements ```json "status_bar": { "active_language_button": true, - "cursor_position_button": true + "cursor_position_button": true, + "encoding_indicator": true, }, ```