diff --git a/Cargo.lock b/Cargo.lock index ce1dfe0a4e5dfcc1009c31d72588bb3aa7c3dc4c..310fd83a406ba39c1825cc53b5e169125b035f40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14868,6 +14868,7 @@ dependencies = [ "collections", "editor", "feature_flags", + "fs", "futures 0.3.31", "gpui", "itertools 0.14.0", diff --git a/crates/search/Cargo.toml b/crates/search/Cargo.toml index 9fa515d4349a34fb4bfd62d5466f651a6ad28057..c9abbe1ee8252e5cb1c571d513dfa0d579ad3658 100644 --- a/crates/search/Cargo.toml +++ b/crates/search/Cargo.toml @@ -27,6 +27,7 @@ bitflags.workspace = true collections.workspace = true editor.workspace = true feature_flags.workspace = true +fs.workspace = true futures.workspace = true gpui.workspace = true language.workspace = true diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index def14d9660fb367440bc7e54e675cfc4bfff0fff..90cc36771eb2df6a08140559516a02c36e1773c8 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -30,11 +30,15 @@ use project::{ search_history::{SearchHistory, SearchHistoryCursor}, }; -use settings::Settings; +use fs::Fs; +use settings::{DiffViewStyle, Settings, update_settings_file}; use std::{any::TypeId, sync::Arc}; use zed_actions::{outline::ToggleOutline, workspace::CopyPath, workspace::CopyRelativePath}; -use ui::{BASE_REM_SIZE_IN_PX, IconButtonShape, Tooltip, prelude::*, utils::SearchInputWidth}; +use ui::{ + BASE_REM_SIZE_IN_PX, IconButtonShape, PlatformStyle, TextSize, Tooltip, prelude::*, + render_modifiers, utils::SearchInputWidth, +}; use util::{ResultExt, paths::PathMatcher}; use workspace::{ ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace, @@ -118,33 +122,89 @@ impl Render for BufferSearchBar { IconButton::new("diff-stacked", IconName::DiffStacked) .shape(IconButtonShape::Square) .toggle_state(!is_split) - .tooltip(|_, cx| { - Tooltip::for_action("Stacked", &ToggleDiffView, cx) - }) - .when(is_split, |button| { + .tooltip(Tooltip::element(move |_, cx| { + v_flex() + .gap_1() + .child(Label::new("Stacked")) + .child( + h_flex() + .gap_0p5() + .text_sm() + .text_color(Color::Muted.color(cx)) + .children(render_modifiers( + &gpui::Modifiers::secondary_key(), + PlatformStyle::platform(), + None, + Some(TextSize::Default.rems(cx).into()), + false, + )) + .child("click to set as default"), + ) + .into_any() + })) + .on_click({ let focus_handle = focus_handle.clone(); - button.on_click(move |_, window, cx| { - focus_handle.focus(window, cx); - window.dispatch_action(ToggleDiffView.boxed_clone(), cx); - }) + move |_, window, cx| { + if window.modifiers().secondary() { + update_settings_file( + ::global(cx), + cx, + |settings, _| { + settings.editor.diff_view_style = + Some(DiffViewStyle::Stacked); + }, + ); + } + if is_split { + focus_handle.focus(window, cx); + window + .dispatch_action(ToggleDiffView.boxed_clone(), cx); + } + } }), ) .child( IconButton::new("diff-split", IconName::DiffSplit) .shape(IconButtonShape::Square) .toggle_state(is_split) - .tooltip(|_, cx| { - Tooltip::for_action("Side by Side", &ToggleDiffView, cx) - }) - .when(!is_split, |button| { - button.on_click({ - let focus_handle = focus_handle.clone(); - move |_, window, cx| { + .tooltip(Tooltip::element(move |_, cx| { + v_flex() + .gap_1() + .child(Label::new("Side by Side")) + .child( + h_flex() + .gap_0p5() + .text_sm() + .text_color(Color::Muted.color(cx)) + .children(render_modifiers( + &gpui::Modifiers::secondary_key(), + PlatformStyle::platform(), + None, + Some(TextSize::Default.rems(cx).into()), + false, + )) + .child("click to set as default"), + ) + .into_any() + })) + .on_click({ + move |_, window, cx| { + if window.modifiers().secondary() { + update_settings_file( + ::global(cx), + cx, + |settings, _| { + settings.editor.diff_view_style = + Some(DiffViewStyle::SideBySide); + }, + ); + } + if !is_split { focus_handle.focus(window, cx); window .dispatch_action(ToggleDiffView.boxed_clone(), cx); } - }) + } }), ) })