From f8b91bd0f0d64b41e18af9121dd4864bfddb52f2 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 16 Nov 2023 18:36:19 +0100 Subject: [PATCH] Fix some of the warnings --- 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(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 7f2d2b09101ca85683068b22f69dbba192507fcb..021cc570158d9b31bac1b56f58bac3e6247f2749 100644 --- a/crates/search2/src/buffer_search.rs +++ b/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| { + 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| { + 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( + workspace: &mut Workspace, + update: fn(&mut BufferSearchBar, &A, &mut ViewContext), + ) { + 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::() { + 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 { 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) -> impl Component { + fn render_action_button(&self) -> impl Component { // 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) { - dbg!(&event); match event { SearchEvent::MatchesInvalidated => { let _ = self.update_matches(cx); diff --git a/crates/search2/src/mode.rs b/crates/search2/src/mode.rs index 8afc2bd3f496cc502f5ffd53fec5b05973108501..bb729cb6c0c198cb1034f04a31125b6df7325e96 100644 --- a/crates/search2/src/mode.rs +++ b/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 { diff --git a/crates/search2/src/search_bar.rs b/crates/search2/src/search_bar.rs index 1c77a03741de5b2e9f47324e1311a7a5830a6c75..46a3357763cbe6188ade787fdf45417a022d39e6 100644 --- a/crates/search2/src/search_bar.rs +++ b/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( icon: ui::Icon, - direction: Direction, - active: bool, on_click: impl Fn(&mut V, &mut ViewContext) + 'static + Send + Sync, - cx: &mut ViewContext, ) -> impl Component { // let tooltip_style = cx.theme().tooltip.clone(); // let cursor_style = if active { @@ -22,57 +19,13 @@ pub(super) fn render_nav_button( // }; // enum NavButton {} IconButton::new("search-nav-button", icon).on_click(on_click) - // MouseEventHandler::new::(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::( - // direction as usize, - // tooltip.to_string(), - // Some(action), - // tooltip_style, - // cx, - // ) - // .into_any() } pub(crate) fn render_search_mode_button( mode: SearchMode, - side: Option, is_active: bool, on_click: impl Fn(&mut V, &mut ViewContext) + 'static + Send + Sync, - cx: &mut ViewContext, ) -> Button { - //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( 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::(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::( - // mode.region_id(), - // mode.tooltip_text().to_owned(), - // Some(mode.activate_action()), - // tooltip_style, - // cx, - // ) - // .into_any() } pub(crate) fn render_option_button_icon( @@ -150,8 +43,6 @@ pub(crate) fn render_option_button_icon( id: usize, label: impl Into>, action: Box, - //on_click: impl Fn(MouseClick, &mut V, &mut EventContext) + 'static, - cx: &mut ViewContext, ) -> impl Component { //let tooltip_style = cx.theme().tooltip.clone(); div() diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rs index 14391ca2b2f357f56f084a5688601182bad780cf..2ed7c8f47247cb4fe63e825ca00f4911c7cdfbf0 100644 --- a/crates/terminal_view2/src/terminal_view.rs +++ b/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> {