From 45f7ab876f499616bef30bbfe771971bcbff0358 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:52:34 +0100 Subject: [PATCH 1/3] buffer search: Fix up rough edges Focus query editor when Deploy::focused is true, add missing bindings --- .../quick_action_bar2/src/quick_action_bar.rs | 8 +++-- crates/search2/src/buffer_search.rs | 31 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/crates/quick_action_bar2/src/quick_action_bar.rs b/crates/quick_action_bar2/src/quick_action_bar.rs index e933689e62..3eba0e60ec 100644 --- a/crates/quick_action_bar2/src/quick_action_bar.rs +++ b/crates/quick_action_bar2/src/quick_action_bar.rs @@ -5,7 +5,7 @@ use gpui::{ Action, ClickEvent, Div, ElementId, EventEmitter, InteractiveElement, ParentElement, Render, Stateful, Styled, Subscription, View, ViewContext, WeakView, }; -use search::BufferSearchBar; +use search::{buffer_search, BufferSearchBar}; use ui::{prelude::*, ButtonSize, ButtonStyle, Icon, IconButton, IconSize, Tooltip}; use workspace::{ item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace, @@ -64,12 +64,14 @@ impl Render for QuickActionBar { "toggle buffer search", Icon::MagnifyingGlass, !self.buffer_search_bar.read(cx).is_dismissed(), - Box::new(search::buffer_search::Deploy { focus: false }), + Box::new(buffer_search::Deploy { focus: false }), "Buffer Search", { let buffer_search_bar = self.buffer_search_bar.clone(); move |_, cx| { - buffer_search_bar.update(cx, |search_bar, cx| search_bar.toggle(cx)); + buffer_search_bar.update(cx, |search_bar, cx| { + search_bar.toggle(&buffer_search::Deploy { focus: true }, cx) + }); } }, )) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index da32f51194..4ea0226d48 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -11,8 +11,8 @@ use editor::{Editor, EditorMode}; use futures::channel::oneshot; use gpui::{ actions, div, red, Action, AppContext, Div, EventEmitter, FocusableView, - InteractiveElement as _, IntoElement, ParentElement as _, Render, Styled, Subscription, Task, - View, ViewContext, VisualContext as _, WeakView, WindowContext, + InteractiveElement as _, IntoElement, KeyContext, ParentElement as _, Render, Styled, + Subscription, Task, View, ViewContext, VisualContext as _, WeakView, WindowContext, }; use project::search::SearchQuery; use serde::Deserialize; @@ -170,14 +170,19 @@ impl Render for BufferSearchBar { h_stack() .key_context("BufferSearchBar") - .when(in_replace, |this| { - this.key_context("in_replace") - .on_action(cx.listener(Self::replace_next)) - .on_action(cx.listener(Self::replace_all)) - }) .on_action(cx.listener(Self::previous_history_query)) .on_action(cx.listener(Self::next_history_query)) .on_action(cx.listener(Self::dismiss)) + .on_action(cx.listener(Self::select_next_match)) + .on_action(cx.listener(Self::select_prev_match)) + .when(self.supported_options().replacement, |this| { + this.on_action(cx.listener(Self::toggle_replace)) + .when(in_replace, |this| { + this.key_context("in_replace") + .on_action(cx.listener(Self::replace_next)) + .on_action(cx.listener(Self::replace_all)) + }) + }) .w_full() .p_1() .child( @@ -305,7 +310,7 @@ impl BufferSearchBar { let handle = cx.view().downgrade(); - editor.register_action(move |a: &Deploy, cx| { + editor.register_action(move |deploy: &Deploy, cx| { let Some(pane) = handle.upgrade().and_then(|editor| editor.read(cx).pane(cx)) else { return; }; @@ -313,12 +318,12 @@ impl BufferSearchBar { pane.update(cx, |this, cx| { this.toolbar().update(cx, |this, cx| { if let Some(search_bar) = this.item_of_type::() { - search_bar.update(cx, |this, cx| this.toggle(cx)); + search_bar.update(cx, |this, cx| this.toggle(deploy, cx)); return; } let view = cx.build_view(|cx| BufferSearchBar::new(cx)); this.add_item(view.clone(), cx); - view.update(cx, |this, cx| this.deploy(a, cx)); + view.update(cx, |this, cx| this.deploy(deploy, cx)); cx.notify(); }) }); @@ -468,7 +473,7 @@ impl BufferSearchBar { self.search_suggested(cx); if deploy.focus { self.select_query(cx); - let handle = cx.focus_handle(); + let handle = self.query_editor.focus_handle(cx); cx.focus(&handle); } return true; @@ -477,9 +482,9 @@ impl BufferSearchBar { false } - pub fn toggle(&mut self, cx: &mut ViewContext) { + pub fn toggle(&mut self, action: &Deploy, cx: &mut ViewContext) { if self.is_dismissed() { - self.show(cx); + self.deploy(action, cx); } else { self.dismiss(&Dismiss, cx); } From 18393d1fac311d1205318c35b0e0a7e703a0bd7d Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:13:38 +0100 Subject: [PATCH 2/3] fixup! buffer search: Fix up rough edges --- crates/search2/src/buffer_search.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 4ea0226d48..285f37d5cb 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -183,6 +183,12 @@ impl Render for BufferSearchBar { .on_action(cx.listener(Self::replace_all)) }) }) + .when(self.supported_options().case, |this| { + this.on_action(cx.listener(Self::toggle_case_sensitive)) + }) + .when(self.supported_options().word, |this| { + this.on_action(cx.listener(Self::toggle_whole_word)) + }) .w_full() .p_1() .child( From 8839bfa1df8018994ebbba90f672b5f882823d3b Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:54:51 +0100 Subject: [PATCH 3/3] Remove unused import --- crates/search2/src/buffer_search.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 285f37d5cb..cbbeeb0f12 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -11,8 +11,8 @@ use editor::{Editor, EditorMode}; use futures::channel::oneshot; use gpui::{ actions, div, red, Action, AppContext, Div, EventEmitter, FocusableView, - InteractiveElement as _, IntoElement, KeyContext, ParentElement as _, Render, Styled, - Subscription, Task, View, ViewContext, VisualContext as _, WeakView, WindowContext, + InteractiveElement as _, IntoElement, ParentElement as _, Render, Styled, Subscription, Task, + View, ViewContext, VisualContext as _, WeakView, WindowContext, }; use project::search::SearchQuery; use serde::Deserialize;