diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index dbee215a11..4334e1336e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -716,18 +716,39 @@ impl ScrollbarMarkerState { #[derive(Clone, Copy, PartialEq, Eq)] pub enum MinimapVisibility { Disabled, - Enabled(bool), + Enabled { + /// The configuration currently present in the users settings. + setting_configuration: bool, + /// Whether to override the currently set visibility from the users setting. + toggle_override: bool, + }, } impl MinimapVisibility { fn for_mode(mode: &EditorMode, cx: &App) -> Self { if mode.is_full() { - Self::Enabled(EditorSettings::get_global(cx).minimap.minimap_enabled()) + Self::Enabled { + setting_configuration: EditorSettings::get_global(cx).minimap.minimap_enabled(), + toggle_override: false, + } } else { Self::Disabled } } + fn hidden(&self) -> Self { + match *self { + Self::Enabled { + setting_configuration, + .. + } => Self::Enabled { + setting_configuration, + toggle_override: setting_configuration, + }, + Self::Disabled => Self::Disabled, + } + } + fn disabled(&self) -> bool { match *self { Self::Disabled => true, @@ -735,16 +756,35 @@ impl MinimapVisibility { } } + fn settings_visibility(&self) -> bool { + match *self { + Self::Enabled { + setting_configuration, + .. + } => setting_configuration, + _ => false, + } + } + fn visible(&self) -> bool { match *self { - Self::Enabled(visible) => visible, + Self::Enabled { + setting_configuration, + toggle_override, + } => setting_configuration ^ toggle_override, _ => false, } } fn toggle_visibility(&self) -> Self { match *self { - Self::Enabled(visible) => Self::Enabled(!visible), + Self::Enabled { + toggle_override, + setting_configuration, + } => Self::Enabled { + setting_configuration, + toggle_override: !toggle_override, + }, Self::Disabled => Self::Disabled, } } @@ -16979,6 +17019,10 @@ impl Editor { self.set_minimap_visibility(MinimapVisibility::Disabled, window, cx); } + pub fn hide_minimap_by_default(&mut self, window: &mut Window, cx: &mut Context) { + self.set_minimap_visibility(self.minimap_visibility.hidden(), window, cx); + } + /// Normally the text in full mode and auto height editors is padded on the /// left side by roughly half a character width for improved hit testing. /// @@ -18518,9 +18562,9 @@ impl Editor { } let minimap_settings = EditorSettings::get_global(cx).minimap; - if self.minimap_visibility.visible() != minimap_settings.minimap_enabled() { + if self.minimap_visibility.settings_visibility() != minimap_settings.minimap_enabled() { self.set_minimap_visibility( - self.minimap_visibility.toggle_visibility(), + MinimapVisibility::for_mode(self.mode(), cx), window, cx, ); diff --git a/crates/language_tools/src/lsp_log.rs b/crates/language_tools/src/lsp_log.rs index ef0d5e6d03..3acb1cb2b0 100644 --- a/crates/language_tools/src/lsp_log.rs +++ b/crates/language_tools/src/lsp_log.rs @@ -702,15 +702,7 @@ impl LspLogView { window: &mut Window, cx: &mut Context, ) -> (Entity, Vec) { - let editor = cx.new(|cx| { - let mut editor = Editor::multi_line(window, cx); - editor.set_text(log_contents, window, cx); - editor.move_to_end(&MoveToEnd, window, cx); - editor.set_read_only(true); - editor.set_show_edit_predictions(Some(false), window, cx); - editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); - editor - }); + let editor = initialize_new_editor(log_contents, true, window, cx); let editor_subscription = cx.subscribe( &editor, |_, _, event: &EditorEvent, cx: &mut Context| cx.emit(event.clone()), @@ -727,10 +719,8 @@ impl LspLogView { window: &mut Window, cx: &mut Context, ) -> (Entity, Vec) { - let editor = cx.new(|cx| { - let mut editor = Editor::multi_line(window, cx); - let server_info = format!( - "* Server: {NAME} (id {ID}) + let server_info = format!( + "* Server: {NAME} (id {ID}) * Binary: {BINARY:#?} @@ -740,29 +730,24 @@ impl LspLogView { * Capabilities: {CAPABILITIES} * Configuration: {CONFIGURATION}", - NAME = server.name(), - ID = server.server_id(), - BINARY = server.binary(), - WORKSPACE_FOLDERS = server - .workspace_folders() - .iter() - .filter_map(|path| path - .to_file_path() - .ok() - .map(|path| path.to_string_lossy().into_owned())) - .collect::>() - .join(", "), - CAPABILITIES = serde_json::to_string_pretty(&server.capabilities()) - .unwrap_or_else(|e| format!("Failed to serialize capabilities: {e}")), - CONFIGURATION = serde_json::to_string_pretty(server.configuration()) - .unwrap_or_else(|e| format!("Failed to serialize configuration: {e}")), - ); - editor.set_text(server_info, window, cx); - editor.set_read_only(true); - editor.set_show_edit_predictions(Some(false), window, cx); - editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); - editor - }); + NAME = server.name(), + ID = server.server_id(), + BINARY = server.binary(), + WORKSPACE_FOLDERS = server + .workspace_folders() + .iter() + .filter_map(|path| path + .to_file_path() + .ok() + .map(|path| path.to_string_lossy().into_owned())) + .collect::>() + .join(", "), + CAPABILITIES = serde_json::to_string_pretty(&server.capabilities()) + .unwrap_or_else(|e| format!("Failed to serialize capabilities: {e}")), + CONFIGURATION = serde_json::to_string_pretty(server.configuration()) + .unwrap_or_else(|e| format!("Failed to serialize configuration: {e}")), + ); + let editor = initialize_new_editor(server_info, false, window, cx); let editor_subscription = cx.subscribe( &editor, |_, _, event: &EditorEvent, cx: &mut Context| cx.emit(event.clone()), @@ -1550,6 +1535,29 @@ impl Render for LspLogToolbarItemView { } } +fn initialize_new_editor( + content: String, + move_to_end: bool, + window: &mut Window, + cx: &mut App, +) -> Entity { + cx.new(|cx| { + let mut editor = Editor::multi_line(window, cx); + editor.hide_minimap_by_default(window, cx); + editor.set_text(content, window, cx); + editor.set_show_git_diff_gutter(false, cx); + editor.set_show_runnables(false, cx); + editor.set_show_breakpoints(false, cx); + editor.set_read_only(true); + editor.set_show_edit_predictions(Some(false), window, cx); + editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); + if move_to_end { + editor.move_to_end(&MoveToEnd, window, cx); + } + editor + }) +} + const RPC_MESSAGES: &str = "RPC Messages"; const SERVER_LOGS: &str = "Server Logs"; const SERVER_TRACE: &str = "Server Trace";