Closes #5294 This PR adds a line ending indicator to the status bar, hidden by default as discussed in https://github.com/zed-industries/zed/issues/5294. ### Changes - 8b063a22d8700bed9c93989b9e0f6a064b2e86cf add the indicator and `status_bar.line_endings_button` setting. - ~~9926237b709dd4e25ce58d558fd385d63b405f3b changes `status_bar.line_endings_button` from a boolean to an enum:~~ <details> <summary> show details </summary> - `always` Always show line endings indicator. - `non_native` Indicate when line endings do not match the current platform. - `lf_only` Indicate when using unix-style (LF) line endings only. - `crlf_only` Indicate when using windows-style (CRLF) line endings only. - `never` Do not show line endings indicator. I know this many options might be overdoing it, but I was torn between the pleasant default of `non_native` and the simplicity of `lf_only` / `crlf_only`. My thinking was if one is developing on a project which exclusively uses one line-ending style or the other, it would be nice to be able to configure no-indicator-in-the-happy-case behavior regardless of the platform zed is running on. But I'm not really familiar with any projects that use exclusively CRLF line endings in practice. Is this a scenario worth supporting or just something I dreamed up? </details> - 01174191e4cf337069e7a31b0f0432ae94c52515 rename the action context for `line ending: Toggle` -> `line ending selector: Toggle`. When running the action in the command palette with the old name I felt surprised to be greeted with an additional menu, with the new name it feels more predictable (plus now it matches `language_selector::Toggle`!) ### Future work Hidden status bar items still get padding, creating inconsistent spacing (and it kind of stands out where I placed the line-endings button): <img alt="the gap after the indicator is larger than for other buttons" src="https://github.com/user-attachments/assets/24a346d4-3ff6-4f7f-bd87-64d453c2441a" /> I started a new follow-up PR to address that: https://github.com/zed-industries/zed/pull/39992 Release Notes: - Added line ending indicator to the status bar (disabled by default; enabled by setting `status_bar.line_endings_button` to `true`)
143 lines
5.5 KiB
Rust
143 lines
5.5 KiB
Rust
use std::num::NonZeroUsize;
|
|
|
|
use crate::DockPosition;
|
|
use collections::HashMap;
|
|
use serde::Deserialize;
|
|
pub use settings::AutosaveSetting;
|
|
pub use settings::{
|
|
BottomDockLayout, PaneSplitDirectionHorizontal, PaneSplitDirectionVertical,
|
|
RestoreOnStartupBehavior,
|
|
};
|
|
use settings::{InactiveOpacity, Settings};
|
|
|
|
pub struct WorkspaceSettings {
|
|
pub active_pane_modifiers: ActivePanelModifiers,
|
|
pub bottom_dock_layout: settings::BottomDockLayout,
|
|
pub pane_split_direction_horizontal: settings::PaneSplitDirectionHorizontal,
|
|
pub pane_split_direction_vertical: settings::PaneSplitDirectionVertical,
|
|
pub centered_layout: settings::CenteredLayoutSettings,
|
|
pub confirm_quit: bool,
|
|
pub show_call_status_icon: bool,
|
|
pub autosave: AutosaveSetting,
|
|
pub restore_on_startup: settings::RestoreOnStartupBehavior,
|
|
pub restore_on_file_reopen: bool,
|
|
pub drop_target_size: f32,
|
|
pub use_system_path_prompts: bool,
|
|
pub use_system_prompts: bool,
|
|
pub command_aliases: HashMap<String, String>,
|
|
pub max_tabs: Option<NonZeroUsize>,
|
|
pub when_closing_with_no_tabs: settings::CloseWindowWhenNoItems,
|
|
pub on_last_window_closed: settings::OnLastWindowClosed,
|
|
pub resize_all_panels_in_dock: Vec<DockPosition>,
|
|
pub close_on_file_delete: bool,
|
|
pub use_system_window_tabs: bool,
|
|
pub zoomed_padding: bool,
|
|
}
|
|
|
|
#[derive(Copy, Clone, PartialEq, Debug, Default)]
|
|
pub struct ActivePanelModifiers {
|
|
/// Size of the border surrounding the active pane.
|
|
/// When set to 0, the active pane doesn't have any border.
|
|
/// The border is drawn inset.
|
|
///
|
|
/// Default: `0.0`
|
|
// TODO: make this not an option, it is never None
|
|
pub border_size: Option<f32>,
|
|
/// Opacity of inactive panels.
|
|
/// When set to 1.0, the inactive panes have the same opacity as the active one.
|
|
/// If set to 0, the inactive panes content will not be visible at all.
|
|
/// Values are clamped to the [0.0, 1.0] range.
|
|
///
|
|
/// Default: `1.0`
|
|
// TODO: make this not an option, it is never None
|
|
pub inactive_opacity: Option<InactiveOpacity>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct TabBarSettings {
|
|
pub show: bool,
|
|
pub show_nav_history_buttons: bool,
|
|
pub show_tab_bar_buttons: bool,
|
|
}
|
|
|
|
impl Settings for WorkspaceSettings {
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let workspace = &content.workspace;
|
|
Self {
|
|
active_pane_modifiers: ActivePanelModifiers {
|
|
border_size: Some(
|
|
workspace
|
|
.active_pane_modifiers
|
|
.unwrap()
|
|
.border_size
|
|
.unwrap(),
|
|
),
|
|
inactive_opacity: Some(
|
|
workspace
|
|
.active_pane_modifiers
|
|
.unwrap()
|
|
.inactive_opacity
|
|
.unwrap(),
|
|
),
|
|
},
|
|
bottom_dock_layout: workspace.bottom_dock_layout.unwrap(),
|
|
pane_split_direction_horizontal: workspace.pane_split_direction_horizontal.unwrap(),
|
|
pane_split_direction_vertical: workspace.pane_split_direction_vertical.unwrap(),
|
|
centered_layout: workspace.centered_layout.unwrap(),
|
|
confirm_quit: workspace.confirm_quit.unwrap(),
|
|
show_call_status_icon: workspace.show_call_status_icon.unwrap(),
|
|
autosave: workspace.autosave.unwrap(),
|
|
restore_on_startup: workspace.restore_on_startup.unwrap(),
|
|
restore_on_file_reopen: workspace.restore_on_file_reopen.unwrap(),
|
|
drop_target_size: workspace.drop_target_size.unwrap(),
|
|
use_system_path_prompts: workspace.use_system_path_prompts.unwrap(),
|
|
use_system_prompts: workspace.use_system_prompts.unwrap(),
|
|
command_aliases: workspace.command_aliases.clone(),
|
|
max_tabs: workspace.max_tabs,
|
|
when_closing_with_no_tabs: workspace.when_closing_with_no_tabs.unwrap(),
|
|
on_last_window_closed: workspace.on_last_window_closed.unwrap(),
|
|
resize_all_panels_in_dock: workspace
|
|
.resize_all_panels_in_dock
|
|
.clone()
|
|
.unwrap()
|
|
.into_iter()
|
|
.map(Into::into)
|
|
.collect(),
|
|
close_on_file_delete: workspace.close_on_file_delete.unwrap(),
|
|
use_system_window_tabs: workspace.use_system_window_tabs.unwrap(),
|
|
zoomed_padding: workspace.zoomed_padding.unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Settings for TabBarSettings {
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let tab_bar = content.tab_bar.clone().unwrap();
|
|
TabBarSettings {
|
|
show: tab_bar.show.unwrap(),
|
|
show_nav_history_buttons: tab_bar.show_nav_history_buttons.unwrap(),
|
|
show_tab_bar_buttons: tab_bar.show_tab_bar_buttons.unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct StatusBarSettings {
|
|
pub show: bool,
|
|
pub active_language_button: bool,
|
|
pub cursor_position_button: bool,
|
|
pub line_endings_button: bool,
|
|
}
|
|
|
|
impl Settings for StatusBarSettings {
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let status_bar = content.status_bar.clone().unwrap();
|
|
StatusBarSettings {
|
|
show: status_bar.show.unwrap(),
|
|
active_language_button: status_bar.active_language_button.unwrap(),
|
|
cursor_position_button: status_bar.cursor_position_button.unwrap(),
|
|
line_endings_button: status_bar.line_endings_button.unwrap(),
|
|
}
|
|
}
|
|
}
|