diff --git a/Cargo.lock b/Cargo.lock index 2c2b9b3f58705aad05d719ea58c4164b29b89891..b2955988941ce54f866114368c5f8f54b02f669d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18781,7 +18781,6 @@ dependencies = [ "menu", "schemars", "serde", - "settings", "smallvec", "story", "strum 0.27.2", diff --git a/crates/csv_preview/src/csv_preview.rs b/crates/csv_preview/src/csv_preview.rs index f056f5a12225b000527b9087760e3d683bda1b5b..b0b6ad4186758fd33693d5ee29bd2f0d4d28b816 100644 --- a/crates/csv_preview/src/csv_preview.rs +++ b/crates/csv_preview/src/csv_preview.rs @@ -122,8 +122,9 @@ impl CsvPreviewView { fn new(editor: &Entity, cx: &mut Context) -> Entity { let contents = TableLikeContent::default(); let table_interaction_state = cx.new(|cx| { - TableInteractionState::new(cx) - .with_custom_scrollbar(ui::Scrollbars::for_settings::()) + TableInteractionState::new(cx).with_custom_scrollbar(ui::Scrollbars::for_settings::< + editor::EditorSettingsScrollbarProxy, + >()) }); cx.new(|cx| { diff --git a/crates/editor/src/code_context_menus.rs b/crates/editor/src/code_context_menus.rs index e1ea2822168c836caffd9ef6f59b263c6432d10b..3fc6080b4da8ca85d258d04de29d603ea7097623 100644 --- a/crates/editor/src/code_context_menus.rs +++ b/crates/editor/src/code_context_menus.rs @@ -287,14 +287,9 @@ impl Drop for CompletionsMenu { } } +#[derive(Default)] struct CompletionMenuScrollBarSetting; -impl ui::scrollbars::GlobalSetting for CompletionMenuScrollBarSetting { - fn get_value(_cx: &App) -> &Self { - &Self - } -} - impl ui::scrollbars::ScrollbarVisibility for CompletionMenuScrollBarSetting { fn visibility(&self, cx: &App) -> ui::scrollbars::ShowScrollbar { EditorSettings::get_global(cx).completion_menu_scrollbar diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 2f9af1bf233baca4613ee72c8ca9d82c1ed87ddc..6d9ee235f01782d43bca485d50272bddf306b837 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -61,8 +61,8 @@ pub use display_map::{ pub use edit_prediction_types::Direction; pub use editor_settings::{ CompletionDetailAlignment, CurrentLineHighlight, DiffViewStyle, DocumentColorsRenderMode, - EditorSettings, HideMouseMode, ScrollBeyondLastLine, ScrollbarAxes, SearchSettings, - ShowMinimap, + EditorSettings, EditorSettingsScrollbarProxy, HideMouseMode, ScrollBeyondLastLine, + ScrollbarAxes, SearchSettings, ShowMinimap, ui_scrollbar_settings_from_raw, }; pub use element::{ CursorLayout, EditorElement, HighlightedRange, HighlightedRangeLine, PointForPosition, diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 98283f045853e1df0dab7ffd0955aa52249377e6..fbb2ac703bf8f0617c7fd5e0918821bdbe951d41 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -10,7 +10,7 @@ pub use settings::{ ScrollbarDiagnostics, SeedQuerySetting, ShowMinimap, SnippetSortOrder, }; use settings::{RegisterSetting, RelativeLineNumbers, Settings}; -use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar}; +use ui::scrollbars::ShowScrollbar; /// Imports from the VSCode settings at /// https://code.visualstudio.com/docs/reference/default-settings @@ -183,12 +183,6 @@ impl EditorSettings { } } -impl ScrollbarVisibility for EditorSettings { - fn visibility(&self, _cx: &App) -> ShowScrollbar { - self.scrollbar.show - } -} - impl Settings for EditorSettings { fn from_settings(content: &settings::SettingsContent) -> Self { let editor = content.editor.clone(); @@ -217,7 +211,7 @@ impl Settings for EditorSettings { code_actions: toolbar.code_actions.unwrap(), }, scrollbar: Scrollbar { - show: scrollbar.show.map(Into::into).unwrap(), + show: scrollbar.show.map(ui_scrollbar_settings_from_raw).unwrap(), git_diff: scrollbar.git_diff.unwrap() && content .git @@ -294,9 +288,32 @@ impl Settings for EditorSettings { }, lsp_document_colors: editor.lsp_document_colors.unwrap(), minimum_contrast_for_highlights: editor.minimum_contrast_for_highlights.unwrap().0, - completion_menu_scrollbar: editor.completion_menu_scrollbar.map(Into::into).unwrap(), + completion_menu_scrollbar: editor + .completion_menu_scrollbar + .map(ui_scrollbar_settings_from_raw) + .unwrap(), completion_detail_alignment: editor.completion_detail_alignment.unwrap(), diff_view_style: editor.diff_view_style.unwrap(), } } } + +#[derive(Default)] +pub struct EditorSettingsScrollbarProxy; + +impl ui::scrollbars::ScrollbarVisibility for EditorSettingsScrollbarProxy { + fn visibility(&self, cx: &App) -> ShowScrollbar { + EditorSettings::get_global(cx).scrollbar.show + } +} + +pub fn ui_scrollbar_settings_from_raw( + value: settings::ShowScrollbar, +) -> ui::scrollbars::ShowScrollbar { + match value { + settings::ShowScrollbar::Auto => ShowScrollbar::Auto, + settings::ShowScrollbar::System => ShowScrollbar::System, + settings::ShowScrollbar::Always => ShowScrollbar::Always, + settings::ShowScrollbar::Never => ShowScrollbar::Never, + } +} diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index 791f0d67a14a949cd3eb916a2831f097ba320d91..9b127a8f1bc089d9cee28254c6b8ffc181677765 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -2,6 +2,7 @@ use crate::{ ActiveDiagnostic, Anchor, AnchorRangeExt, DisplayPoint, DisplayRow, Editor, EditorSettings, EditorSnapshot, GlobalDiagnosticRenderer, HighlightKey, Hover, display_map::{InlayOffset, ToDisplayPoint, is_invisible}, + editor_settings::EditorSettingsScrollbarProxy, hover_links::{InlayHighlight, RangeInEditor}, movement::TextLayoutDetails, scroll::ScrollAmount, @@ -1048,7 +1049,7 @@ impl InfoPopover { ), ) .custom_scrollbars( - Scrollbars::for_settings::() + Scrollbars::for_settings::() .tracked_scroll_handle(&self.scroll_handle), window, cx, @@ -1176,7 +1177,7 @@ impl DiagnosticPopover { CopyButton::new("copy-diagnostic", message).tooltip_label("Copy Diagnostic") })) .custom_scrollbars( - Scrollbars::for_settings::() + Scrollbars::for_settings::() .tracked_scroll_handle(&self.scroll_handle), window, cx, diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 00058ee82bb8df15e63d96771f481833310f09f5..d8ef930cb2509b0e92b7fe8f90c4cbaf4121132c 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -2,6 +2,7 @@ use crate::askpass_modal::AskPassModal; use crate::commit_modal::CommitModal; use crate::commit_tooltip::CommitTooltip; use crate::commit_view::CommitView; +use crate::git_panel_settings::GitPanelScrollbarAccessor; use crate::project_diff::{self, BranchDiff, Diff, ProjectDiff}; use crate::remote_output::{self, RemoteAction, SuccessMessage}; use crate::{branch_picker, picker_prompt, render_remote_button}; @@ -4885,7 +4886,7 @@ impl GitPanel { }), ) .custom_scrollbars( - Scrollbars::for_settings::() + Scrollbars::for_settings::() .tracked_scroll_handle(&self.scroll_handle) .with_track_along( ScrollAxes::Horizontal, diff --git a/crates/git_ui/src/git_panel_settings.rs b/crates/git_ui/src/git_panel_settings.rs index 16a1113b60a53544834f1484a2fa7e6fcbea9aca..9ccbced249db6707f1b5bca609f5dddea47bbd6a 100644 --- a/crates/git_ui/src/git_panel_settings.rs +++ b/crates/git_ui/src/git_panel_settings.rs @@ -1,4 +1,4 @@ -use editor::EditorSettings; +use editor::{EditorSettings, ui_scrollbar_settings_from_raw}; use gpui::Pixels; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -32,7 +32,10 @@ pub struct GitPanelSettings { pub starts_open: bool, } -impl ScrollbarVisibility for GitPanelSettings { +#[derive(Default)] +pub(crate) struct GitPanelScrollbarAccessor; + +impl ScrollbarVisibility for GitPanelScrollbarAccessor { fn visibility(&self, cx: &ui::App) -> ShowScrollbar { // TODO: This PR should have defined Editor's `scrollbar.axis` // as an Option, not a ScrollbarAxes as it would allow you to @@ -42,7 +45,8 @@ impl ScrollbarVisibility for GitPanelSettings { // so we can show each axis based on the settings. // // We should fix this. PR: https://github.com/zed-industries/zed/pull/19495 - self.scrollbar + GitPanelSettings::get_global(cx) + .scrollbar .show .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show) } @@ -59,7 +63,11 @@ impl Settings for GitPanelSettings { file_icons: git_panel.file_icons.unwrap(), folder_icons: git_panel.folder_icons.unwrap(), scrollbar: ScrollbarSettings { - show: git_panel.scrollbar.unwrap().show.map(Into::into), + show: git_panel + .scrollbar + .unwrap() + .show + .map(ui_scrollbar_settings_from_raw), }, fallback_branch_name: git_panel.fallback_branch_name.unwrap(), sort_by_path: git_panel.sort_by_path.unwrap(), diff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rs index bc92763a770ce1f10a30851595a61c530f7482c2..6a02289353f7fc0df8fd2b3fd99313d2ce650951 100644 --- a/crates/keymap_editor/src/keymap_editor.rs +++ b/crates/keymap_editor/src/keymap_editor.rs @@ -542,8 +542,9 @@ impl KeymapEditor { let _keymap_subscription = cx.observe_global_in::(window, Self::on_keymap_changed); let table_interaction_state = cx.new(|cx| { - TableInteractionState::new(cx) - .with_custom_scrollbar(ui::Scrollbars::for_settings::()) + TableInteractionState::new(cx).with_custom_scrollbar(ui::Scrollbars::for_settings::< + editor::EditorSettingsScrollbarProxy, + >()) }); let keystroke_editor = cx.new(|cx| { @@ -2184,7 +2185,7 @@ impl Render for KeymapEditor { .cloned() .unwrap_or_default() .into_any_element(), - |binding| ui::KeyBinding::from_keystrokes(binding.keystrokes.clone(), binding.source).into_any_element() + |binding| ui::KeyBinding::from_keystrokes(binding.keystrokes.clone(), binding.source == KeybindSource::Vim).into_any_element() ); let action_arguments = match binding.action().arguments.clone() diff --git a/crates/outline_panel/src/outline_panel.rs b/crates/outline_panel/src/outline_panel.rs index 141c31a269073605f5ddc5fe4cc7fd6bdd553a35..aa6f89cb8c11c40d4121ab12720069ee7fe66844 100644 --- a/crates/outline_panel/src/outline_panel.rs +++ b/crates/outline_panel/src/outline_panel.rs @@ -62,6 +62,8 @@ use workspace::{ }; use worktree::{Entry, ProjectEntryId, WorktreeId}; +use crate::outline_panel_settings::OutlinePanelSettingsScrollbarProxy; + actions!( outline_panel, [ @@ -4805,7 +4807,7 @@ impl OutlinePanel { .size_full() .child(list_contents.size_full().flex_shrink()) .custom_scrollbars( - Scrollbars::for_settings::() + Scrollbars::for_settings::() .tracked_scroll_handle(&self.scroll_handle.clone()) .with_track_along( ScrollAxes::Horizontal, diff --git a/crates/outline_panel/src/outline_panel_settings.rs b/crates/outline_panel/src/outline_panel_settings.rs index b744ca6399dd16ad216d1cb4c6dda5e1d93baa4b..18f52e512da24ee986e9fe3f49ff5e3cd08c8b23 100644 --- a/crates/outline_panel/src/outline_panel_settings.rs +++ b/crates/outline_panel/src/outline_panel_settings.rs @@ -1,4 +1,4 @@ -use editor::EditorSettings; +use editor::{EditorSettings, ui_scrollbar_settings_from_raw}; use gpui::{App, Pixels}; use settings::RegisterSetting; pub use settings::{DockSide, Settings, ShowIndentGuides}; @@ -33,9 +33,13 @@ pub struct IndentGuidesSettings { pub show: ShowIndentGuides, } -impl ScrollbarVisibility for OutlinePanelSettings { +#[derive(Default)] +pub(crate) struct OutlinePanelSettingsScrollbarProxy; + +impl ScrollbarVisibility for OutlinePanelSettingsScrollbarProxy { fn visibility(&self, cx: &App) -> ShowScrollbar { - self.scrollbar + OutlinePanelSettings::get_global(cx) + .scrollbar .show .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show) } @@ -65,7 +69,11 @@ impl Settings for OutlinePanelSettings { auto_reveal_entries: panel.auto_reveal_entries.unwrap(), auto_fold_dirs: panel.auto_fold_dirs.unwrap(), scrollbar: ScrollbarSettings { - show: panel.scrollbar.unwrap().show.map(Into::into), + show: panel + .scrollbar + .unwrap() + .show + .map(ui_scrollbar_settings_from_raw), }, expand_outlines_with_depth: panel.expand_outlines_with_depth.unwrap(), } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index aa8c86091d526165f3406016ee49d86a30596c37..599afd99b37cee5602934a14df117b6162819806 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -82,7 +82,10 @@ use zed_actions::{ workspace::OpenWithSystem, }; -use crate::undo::{ProjectPanelOperation, UndoManager}; +use crate::{ + project_panel_settings::ProjectPanelScrollbarProxy, + undo::{ProjectPanelOperation, UndoManager}, +}; const PROJECT_PANEL_KEY: &str = "ProjectPanel"; const NEW_ENTRY_ID: ProjectEntryId = ProjectEntryId::MAX; @@ -7038,8 +7041,9 @@ impl Render for ProjectPanel { ) .custom_scrollbars( { - let mut scrollbars = Scrollbars::for_settings::() - .tracked_scroll_handle(&self.scroll_handle); + let mut scrollbars = + Scrollbars::for_settings::() + .tracked_scroll_handle(&self.scroll_handle); if horizontal_scroll { scrollbars = scrollbars.with_track_along( ScrollAxes::Horizontal, diff --git a/crates/project_panel/src/project_panel_settings.rs b/crates/project_panel/src/project_panel_settings.rs index d3786f371fdf1878dec39cd7b32f2f2dcfd90877..64f3ea42928399201c497ba58041ed0bf6ed5ba1 100644 --- a/crates/project_panel/src/project_panel_settings.rs +++ b/crates/project_panel/src/project_panel_settings.rs @@ -1,4 +1,4 @@ -use editor::EditorSettings; +use editor::{EditorSettings, ui_scrollbar_settings_from_raw}; use gpui::Pixels; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -81,9 +81,13 @@ impl AutoOpenSettings { } } -impl ScrollbarVisibility for ProjectPanelSettings { +#[derive(Default)] +pub(crate) struct ProjectPanelScrollbarProxy; + +impl ScrollbarVisibility for ProjectPanelScrollbarProxy { fn visibility(&self, cx: &ui::App) -> ShowScrollbar { - self.scrollbar + ProjectPanelSettings::get_global(cx) + .scrollbar .show .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show) } @@ -120,7 +124,7 @@ impl Settings for ProjectPanelSettings { scrollbar: { let scrollbar = project_panel.scrollbar.unwrap(); ScrollbarSettings { - show: scrollbar.show.map(Into::into), + show: scrollbar.show.map(ui_scrollbar_settings_from_raw), horizontal_scroll: scrollbar.horizontal_scroll.unwrap(), } }, diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 98b37eee576d3c9a5b21def618133c1b9fe53e37..b97a0845dbac5447158db01179dbf0849c72ea87 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -6,7 +6,10 @@ pub mod terminal_scrollbar; mod terminal_slash_command; use assistant_slash_command::SlashCommandRegistry; -use editor::{Editor, EditorSettings, actions::SelectAll, blink_manager::BlinkManager}; +use editor::{ + Editor, EditorSettings, actions::SelectAll, blink_manager::BlinkManager, + ui_scrollbar_settings_from_raw, +}; use gpui::{ Action, AnyElement, App, ClipboardEntry, DismissEvent, Entity, EventEmitter, ExternalPaths, FocusHandle, Focusable, Font, KeyContext, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent, @@ -48,7 +51,7 @@ use terminal_slash_command::TerminalSlashCommand; use ui::{ ContextMenu, Divider, ScrollAxes, Scrollbars, Tooltip, WithScrollbar, prelude::*, - scrollbars::{self, GlobalSetting, ScrollbarVisibility}, + scrollbars::{self, ScrollbarVisibility}, }; use util::ResultExt; use workspace::{ @@ -1121,20 +1124,15 @@ fn regex_search_for_query(query: &SearchQuery) -> Option { } } +#[derive(Default)] struct TerminalScrollbarSettingsWrapper; -impl GlobalSetting for TerminalScrollbarSettingsWrapper { - fn get_value(_cx: &App) -> &Self { - &Self - } -} - impl ScrollbarVisibility for TerminalScrollbarSettingsWrapper { fn visibility(&self, cx: &App) -> scrollbars::ShowScrollbar { TerminalSettings::get_global(cx) .scrollbar .show - .map(Into::into) + .map(ui_scrollbar_settings_from_raw) .unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show) } } diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 6ea1b6d26f700c9c44a8dda5e510d0505d7e7db8..05433bf8eebf78eccbbedff7a4bfcfb39b0022a7 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -23,7 +23,6 @@ itertools.workspace = true menu.workspace = true schemars.workspace = true serde.workspace = true -settings.workspace = true smallvec.workspace = true story = { workspace = true, optional = true } strum.workspace = true diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index 6c7efa4e49ee93fd13407c03cf383ff3385bacc7..016181ee9bd22aba1dd937220df03212aa390153 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -8,7 +8,6 @@ use gpui::{ Modifiers, Window, relative, }; use itertools::Itertools; -use settings::KeybindSource; #[derive(Debug)] enum Source { @@ -103,11 +102,11 @@ impl KeyBinding { } } - pub fn from_keystrokes(keystrokes: Rc<[KeybindingKeystroke]>, source: KeybindSource) -> Self { + pub fn from_keystrokes(keystrokes: Rc<[KeybindingKeystroke]>, vim_mode: bool) -> Self { Self { source: Source::Keystrokes { keystrokes }, size: None, - vim_mode: source == KeybindSource::Vim, + vim_mode, platform_style: PlatformStyle::platform(), disabled: false, } diff --git a/crates/ui/src/components/keybinding_hint.rs b/crates/ui/src/components/keybinding_hint.rs index 7c19953ca43c907070829f7140f97a4fde495b57..9da470c4ee417321c61d1834c1256dd41316aedf 100644 --- a/crates/ui/src/components/keybinding_hint.rs +++ b/crates/ui/src/components/keybinding_hint.rs @@ -14,11 +14,10 @@ use theme::Appearance; /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; -/// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::new( -/// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-s").unwrap())].into(), KeybindSource::Base), +/// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-s").unwrap())].into(), false), /// Hsla::black() /// ) /// .prefix("Save:") @@ -46,11 +45,10 @@ impl KeybindingHint { /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; - /// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::new( - /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-c").unwrap())].into(), KeybindSource::Base), + /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-c").unwrap())].into(), false), /// Hsla::black() /// ); /// # } @@ -76,12 +74,11 @@ impl KeybindingHint { /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; - /// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::with_prefix( /// "Copy:", - /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-c").unwrap())].into(), KeybindSource::Base), + /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-c").unwrap())].into(), false), /// Hsla::black() /// ); /// # } @@ -111,11 +108,10 @@ impl KeybindingHint { /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; - /// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::with_suffix( - /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-v").unwrap())].into(), KeybindSource::Base), + /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-v").unwrap())].into(), false), /// "Paste", /// Hsla::black() /// ); @@ -145,11 +141,10 @@ impl KeybindingHint { /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; - /// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::new( - /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-x").unwrap())].into(), KeybindSource::Base), + /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-x").unwrap())].into(), false), /// Hsla::black() /// ) /// .prefix("Cut:"); @@ -170,11 +165,10 @@ impl KeybindingHint { /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; - /// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::new( - /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-f").unwrap())].into(), KeybindSource::Base), + /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-f").unwrap())].into(), false), /// Hsla::black() /// ) /// .suffix("Find"); @@ -195,11 +189,10 @@ impl KeybindingHint { /// use gpui::{App, Hsla, KeybindingKeystroke, Keystroke}; /// use ui::prelude::*; /// use ui::{KeyBinding, KeybindingHint}; - /// use settings::KeybindSource; /// /// # fn example(cx: &App) { /// let hint = KeybindingHint::new( - /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-z").unwrap())].into(), KeybindSource::Base), + /// KeyBinding::from_keystrokes(vec![KeybindingKeystroke::from_keystroke(Keystroke::parse("ctrl-z").unwrap())].into(), false), /// Hsla::black() /// ) /// .size(Pixels::from(16.0)); diff --git a/crates/ui/src/components/scrollbar.rs b/crates/ui/src/components/scrollbar.rs index 795c5174fb42d3caeec3052d3c636b0408ac7ed6..86f5e3b4ccbe80dd340cbeafb52ed499bb79895a 100644 --- a/crates/ui/src/components/scrollbar.rs +++ b/crates/ui/src/components/scrollbar.rs @@ -16,7 +16,6 @@ use gpui::{ size, }; use gpui_util::ResultExt; -use settings::SettingsStore; use smallvec::SmallVec; use theme::ActiveTheme as _; @@ -34,7 +33,6 @@ pub mod scrollbars { use gpui::{App, Global}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; - use settings::Settings; /// When to show the scrollbar in the editor. /// @@ -54,28 +52,7 @@ pub mod scrollbars { Never, } - impl From for ShowScrollbar { - fn from(value: settings::ShowScrollbar) -> Self { - match value { - settings::ShowScrollbar::Auto => ShowScrollbar::Auto, - settings::ShowScrollbar::System => ShowScrollbar::System, - settings::ShowScrollbar::Always => ShowScrollbar::Always, - settings::ShowScrollbar::Never => ShowScrollbar::Never, - } - } - } - - pub trait GlobalSetting { - fn get_value(cx: &App) -> &Self; - } - - impl GlobalSetting for T { - fn get_value(cx: &App) -> &T { - T::get_global(cx) - } - } - - pub trait ScrollbarVisibility: GlobalSetting + 'static { + pub trait ScrollbarVisibility: 'static { fn visibility(&self, cx: &App) -> ShowScrollbar; } @@ -103,11 +80,9 @@ where let element_id = config.id.take().unwrap_or_else(|| caller_location.into()); let track_color = config.track_color; - let state = window.use_keyed_state(element_id, cx, |window, cx| { + let state = window.use_keyed_state(element_id, cx, |_, cx| { let parent_id = cx.entity_id(); - ScrollbarStateWrapper( - cx.new(|cx| ScrollbarState::new_from_config(config, parent_id, window, cx)), - ) + ScrollbarStateWrapper(cx.new(|cx| ScrollbarState::new_from_config(config, parent_id, cx))) }); state.update(cx, |state, cx| { @@ -399,8 +374,8 @@ impl Scrollbars { Self::new_with_setting(show_along, |_| ShowScrollbar::Always) } - pub fn for_settings() -> Scrollbars { - Scrollbars::new_with_setting(ScrollAxes::Both, |cx| S::get_value(cx).visibility(cx)) + pub fn for_settings() -> Scrollbars { + Scrollbars::new_with_setting(ScrollAxes::Both, |cx| S::default().visibility(cx)) } } @@ -589,6 +564,16 @@ enum ParentHoverEvent { Outside, } +pub fn on_new_scrollbars(cx: &mut App) { + cx.observe_new::(|_, window, cx| { + if let Some(window) = window { + cx.observe_global_in::(window, ScrollbarState::settings_changed) + .detach(); + } + }) + .detach(); +} + /// This is used to ensure notifies within the state do not notify the parent /// unintentionally. struct ScrollbarStateWrapper(Entity>); @@ -611,15 +596,7 @@ struct ScrollbarState { } impl ScrollbarState { - fn new_from_config( - config: Scrollbars, - parent_id: EntityId, - window: &mut Window, - cx: &mut Context, - ) -> Self { - cx.observe_global_in::(window, Self::settings_changed) - .detach(); - + fn new_from_config(config: Scrollbars, parent_id: EntityId, cx: &mut Context) -> Self { let (manually_added, scroll_handle) = match config.scrollable_handle { Handle::Tracked(handle) => (true, handle), Handle::Untracked(func) => (false, func()), diff --git a/crates/ui/src/components/toggle.rs b/crates/ui/src/components/toggle.rs index 86ff1d8eff8691a2610a4a7e2268aaf47502e306..0b1d7884687b5a3f95c1d54d6a357c4425326f58 100644 --- a/crates/ui/src/components/toggle.rs +++ b/crates/ui/src/components/toggle.rs @@ -2,7 +2,6 @@ use gpui::{ AnyElement, AnyView, ClickEvent, ElementId, Hsla, IntoElement, KeybindingKeystroke, Keystroke, Styled, Window, div, hsla, prelude::*, }; -use settings::KeybindSource; use std::{rc::Rc, sync::Arc}; use crate::utils::is_light; @@ -1051,7 +1050,7 @@ impl Component for Switch { Keystroke::parse("cmd-s").unwrap(), )] .into(), - KeybindSource::Base, + false, ))) .into_any_element(), )], diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index f80608b8aaa4c0bd2b4513de766dc42a73876ab8..25e63abe6ce6b715fa3f5b5e12010f46ac1d4714 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -537,6 +537,7 @@ fn main() { tx.send(Some(options)).log_err(); }) .detach(); + ui::on_new_scrollbars::(cx); let node_runtime = NodeRuntime::new(client.http_client(), Some(shell_env_loaded_rx), rx);