Fix some of the warnings

Piotr Osiewicz created

Change summary

crates/search2/src/buffer_search.rs        |  89 ++++++++++++-------
crates/search2/src/mode.rs                 |   6 -
crates/search2/src/search_bar.rs           | 111 -----------------------
crates/terminal_view2/src/terminal_view.rs |   2 
4 files changed, 58 insertions(+), 150 deletions(-)

Detailed changes

crates/search2/src/buffer_search.rs 🔗

@@ -1,10 +1,10 @@
 use crate::{
     history::SearchHistory,
-    mode::{next_mode, SearchMode, Side},
+    mode::{next_mode, SearchMode},
     search_bar::{render_nav_button, render_search_mode_button},
-    CycleMode, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions,
-    SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleReplace,
-    ToggleWholeWord,
+    ActivateRegexMode, ActivateTextMode, CycleMode, NextHistoryQuery, PreviousHistoryQuery,
+    ReplaceAll, ReplaceNext, SearchOptions, SelectAllMatches, SelectNextMatch, SelectPrevMatch,
+    ToggleCaseSensitive, ToggleReplace, ToggleWholeWord,
 };
 use collections::HashMap;
 use editor::Editor;
@@ -16,7 +16,6 @@ use gpui::{
 };
 use project::search::SearchQuery;
 use std::{any::Any, sync::Arc};
-use theme::ActiveTheme;
 
 use ui::{h_stack, ButtonGroup, Icon, IconButton, IconElement};
 use util::ResultExt;
@@ -129,18 +128,12 @@ impl Render for BufferSearchBar {
             editor.set_placeholder_text("Replace with...", cx);
         });
 
-        let search_button_for_mode = |mode, side, cx: &mut ViewContext<BufferSearchBar>| {
+        let search_button_for_mode = |mode| {
             let is_active = self.current_mode == mode;
 
-            render_search_mode_button(
-                mode,
-                side,
-                is_active,
-                move |this, cx| {
-                    this.activate_search_mode(mode, cx);
-                },
-                cx,
-            )
+            render_search_mode_button(mode, is_active, move |this: &mut Self, cx| {
+                this.activate_search_mode(mode, cx);
+            })
         };
         let search_option_button = |option| {
             let is_active = self.search_options.contains(option);
@@ -164,16 +157,14 @@ impl Render for BufferSearchBar {
 
                 Some(ui::Label::new(message))
             });
-        let nav_button_for_direction = |icon, direction, cx: &mut ViewContext<Self>| {
+        let nav_button_for_direction = |icon, direction| {
             render_nav_button(
                 icon,
-                direction,
                 self.active_match_index.is_some(),
-                move |this, cx| match direction {
+                move |this: &mut Self, cx| match direction {
                     Direction::Prev => this.select_prev_match(&Default::default(), cx),
                     Direction::Next => this.select_next_match(&Default::default(), cx),
                 },
-                cx,
             )
         };
         let should_show_replace_input = self.replace_enabled && supported_options.replacement;
@@ -231,8 +222,8 @@ impl Render for BufferSearchBar {
                 h_stack()
                     .flex_none()
                     .child(ButtonGroup::new(vec![
-                        search_button_for_mode(SearchMode::Text, Some(Side::Left), cx),
-                        search_button_for_mode(SearchMode::Regex, Some(Side::Right), cx),
+                        search_button_for_mode(SearchMode::Text),
+                        search_button_for_mode(SearchMode::Regex),
                     ]))
                     .when(supported_options.replacement, |this| {
                         this.child(super::toggle_replace_button(self.replace_enabled))
@@ -252,17 +243,15 @@ impl Render for BufferSearchBar {
                 h_stack()
                     .gap_0p5()
                     .flex_none()
-                    .child(self.render_action_button(cx))
+                    .child(self.render_action_button())
                     .children(match_count)
                     .child(nav_button_for_direction(
                         ui::Icon::ChevronLeft,
                         Direction::Prev,
-                        cx,
                     ))
                     .child(nav_button_for_direction(
                         ui::Icon::ChevronRight,
                         Direction::Next,
-                        cx,
                     )),
             )
 
@@ -428,6 +417,46 @@ impl BufferSearchBar {
                 })
             });
         });
+        fn register_action<A: Action>(
+            workspace: &mut Workspace,
+            update: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
+        ) {
+            workspace.register_action(move |workspace, action: &A, cx| {
+                workspace.active_pane().update(cx, move |this, cx| {
+                    this.toolbar().update(cx, move |this, cx| {
+                        if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
+                            search_bar.update(cx, move |this, cx| update(this, action, cx));
+                            cx.notify();
+                        }
+                    })
+                });
+            });
+        }
+
+        register_action(workspace, |this, action: &ToggleCaseSensitive, cx| {
+            this.toggle_case_sensitive(action, cx);
+        });
+        register_action(workspace, |this, action: &ToggleWholeWord, cx| {
+            this.toggle_whole_word(action, cx);
+        });
+        register_action(workspace, |this, action: &ToggleReplace, cx| {
+            this.toggle_replace(action, cx);
+        });
+        register_action(workspace, |this, action: &ActivateRegexMode, cx| {
+            this.activate_search_mode(SearchMode::Regex, cx);
+        });
+        register_action(workspace, |this, action: &ActivateTextMode, cx| {
+            this.activate_search_mode(SearchMode::Text, cx);
+        });
+        register_action(workspace, |this, action: &SelectNextMatch, cx| {
+            this.select_next_match(action, cx);
+        });
+        register_action(workspace, |this, action: &SelectPrevMatch, cx| {
+            this.select_prev_match(action, cx);
+        });
+        register_action(workspace, |this, action: &SelectAllMatches, cx| {
+            this.select_all_matches(action, cx);
+        });
     }
     pub fn new(cx: &mut ViewContext<Self>) -> Self {
         let query_editor = cx.build_view(|cx| Editor::single_line(cx));
@@ -587,7 +616,7 @@ impl BufferSearchBar {
         self.update_matches(cx)
     }
 
-    fn render_action_button(&self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
+    fn render_action_button(&self) -> impl Component<Self> {
         // let tooltip_style = theme.tooltip.clone();
 
         // let style = theme.search.action_button.clone();
@@ -686,13 +715,8 @@ impl BufferSearchBar {
                     .searchable_items_with_matches
                     .get(&searchable_item.downgrade())
                 {
-                    let new_match_index = searchable_item.match_index_for_direction(
-                        matches,
-                        index,
-                        direction,
-                        dbg!(count),
-                        cx,
-                    );
+                    let new_match_index = searchable_item
+                        .match_index_for_direction(matches, index, direction, count, cx);
                     searchable_item.update_matches(matches, cx);
                     searchable_item.activate_match(new_match_index, matches, cx);
                 }
@@ -765,7 +789,6 @@ impl BufferSearchBar {
     }
 
     fn on_active_searchable_item_event(&mut self, event: &SearchEvent, cx: &mut ViewContext<Self>) {
-        dbg!(&event);
         match event {
             SearchEvent::MatchesInvalidated => {
                 let _ = self.update_matches(cx);

crates/search2/src/mode.rs 🔗

@@ -10,12 +10,6 @@ pub enum SearchMode {
     Regex,
 }
 
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub(crate) enum Side {
-    Left,
-    Right,
-}
-
 impl SearchMode {
     pub(crate) fn label(&self) -> &'static str {
         match self {

crates/search2/src/search_bar.rs 🔗

@@ -4,15 +4,12 @@ use gpui::{div, Action, Component, ViewContext};
 use ui::{Button, ButtonVariant, IconButton};
 use workspace::searchable::Direction;
 
-use crate::mode::{SearchMode, Side};
+use crate::mode::SearchMode;
 
 pub(super) fn render_nav_button<V: 'static>(
     icon: ui::Icon,
-    direction: Direction,
-
     active: bool,
     on_click: impl Fn(&mut V, &mut ViewContext<V>) + 'static + Send + Sync,
-    cx: &mut ViewContext<V>,
 ) -> impl Component<V> {
     // let tooltip_style = cx.theme().tooltip.clone();
     // let cursor_style = if active {
@@ -22,57 +19,13 @@ pub(super) fn render_nav_button<V: 'static>(
     // };
     // enum NavButton {}
     IconButton::new("search-nav-button", icon).on_click(on_click)
-    // MouseEventHandler::new::<NavButton, _>(direction as usize, cx, |state, cx| {
-    //     let theme = cx.theme();
-    //     let style = theme
-    //         .search
-    //         .nav_button
-    //         .in_state(active)
-    //         .style_for(state)
-    //         .clone();
-    //     let mut container_style = style.container.clone();
-    //     let label = Label::new(icon, style.label.clone()).aligned().contained();
-    //     container_style.corner_radii = match direction {
-    //         Direction::Prev => CornerRadii {
-    //             bottom_right: 0.,
-    //             top_right: 0.,
-    //             ..container_style.corner_radii
-    //         },
-    //         Direction::Next => CornerRadii {
-    //             bottom_left: 0.,
-    //             top_left: 0.,
-    //             ..container_style.corner_radii
-    //         },
-    //     };
-    //     if direction == Direction::Prev {
-    //         // Remove right border so that when both Next and Prev buttons are
-    //         // next to one another, there's no double border between them.
-    //         container_style.border.right = false;
-    //     }
-    //     label.with_style(container_style)
-    // })
-    // .on_click(MouseButton::Left, on_click)
-    // .with_cursor_style(cursor_style)
-    // .with_tooltip::<NavButton>(
-    //     direction as usize,
-    //     tooltip.to_string(),
-    //     Some(action),
-    //     tooltip_style,
-    //     cx,
-    // )
-    // .into_any()
 }
 
 pub(crate) fn render_search_mode_button<V: 'static>(
     mode: SearchMode,
-    side: Option<Side>,
     is_active: bool,
     on_click: impl Fn(&mut V, &mut ViewContext<V>) + 'static + Send + Sync,
-    cx: &mut ViewContext<V>,
 ) -> Button<V> {
-    //let tooltip_style = cx.theme().tooltip.clone();
-    enum SearchModeButton {}
-
     let button_variant = if is_active {
         ButtonVariant::Filled
     } else {
@@ -82,66 +35,6 @@ pub(crate) fn render_search_mode_button<V: 'static>(
     Button::new(mode.label())
         .on_click(Arc::new(on_click))
         .variant(button_variant)
-
-    // v_stack()
-    //     .border_2()
-    //     .rounded_md()
-    //     .when(side == Some(Side::Left), |this| {
-    //         this.border_r_0().rounded_tr_none().rounded_br_none()
-    //     })
-    //     .when(side == Some(Side::Right), |this| {
-    //         this.border_l_0().rounded_bl_none().rounded_tl_none()
-    //     })
-    //     .on_key_down(move |v, _, _, cx| on_click(v, cx))
-    //     .child(Label::new(mode.label()))
-    // MouseEventHandler::new::<SearchModeButton, _>(mode.region_id(), cx, |state, cx| {
-    //     let theme = cx.theme();
-    //     let style = theme
-    //         .search
-    //         .mode_button
-    //         .in_state(is_active)
-    //         .style_for(state)
-    //         .clone();
-
-    //     let mut container_style = style.container;
-    //     if let Some(button_side) = side {
-    //         if button_side == Side::Left {
-    //             container_style.border.left = true;
-    //             container_style.corner_radii = CornerRadii {
-    //                 bottom_right: 0.,
-    //                 top_right: 0.,
-    //                 ..container_style.corner_radii
-    //             };
-    //         } else {
-    //             container_style.border.left = false;
-    //             container_style.corner_radii = CornerRadii {
-    //                 bottom_left: 0.,
-    //                 top_left: 0.,
-    //                 ..container_style.corner_radii
-    //             };
-    //         }
-    //     } else {
-    //         container_style.border.left = false;
-    //         container_style.corner_radii = CornerRadii::default();
-    //     }
-
-    //     Label::new(mode.label(), style.text)
-    //         .aligned()
-    //         .contained()
-    //         .with_style(container_style)
-    //         .constrained()
-    //         .with_height(theme.search.search_bar_row_height)
-    // })
-    // .on_click(MouseButton::Left, on_click)
-    // .with_cursor_style(CursorStyle::PointingHand)
-    // .with_tooltip::<SearchModeButton>(
-    //     mode.region_id(),
-    //     mode.tooltip_text().to_owned(),
-    //     Some(mode.activate_action()),
-    //     tooltip_style,
-    //     cx,
-    // )
-    // .into_any()
 }
 
 pub(crate) fn render_option_button_icon<V: 'static>(
@@ -150,8 +43,6 @@ pub(crate) fn render_option_button_icon<V: 'static>(
     id: usize,
     label: impl Into<Cow<'static, str>>,
     action: Box<dyn Action>,
-    //on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
-    cx: &mut ViewContext<V>,
 ) -> impl Component<V> {
     //let tooltip_style = cx.theme().tooltip.clone();
     div()

crates/terminal_view2/src/terminal_view.rs 🔗

@@ -792,7 +792,7 @@ impl Item for TerminalView {
     // }
 
     fn breadcrumb_location(&self) -> ToolbarItemLocation {
-        ToolbarItemLocation::PrimaryLeft { flex: None }
+        ToolbarItemLocation::PrimaryLeft
     }
 
     fn breadcrumbs(&self, _: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {