Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into project_search2

Piotr Osiewiczddbd5cf2cb50
diff --cc crates/search2/src/project_search.rs
index 3768f00b423,13b53f4dc2d..8e1850e6783
--- a/crates/search2/src/project_search.rs
+++ b/crates/search2/src/project_search.rs
@@@ -1,20 -1,24 +1,19 @@@
use crate::{
- history::SearchHistory, mode::SearchMode, ActivateRegexMode, ActivateSemanticMode,
- ActivateTextMode, CycleMode, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext,
- SearchOptions, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleReplace,
- ToggleWholeWord,
- history::SearchHistory,
- mode::{SearchMode, Side},
- search_bar::{render_nav_button, render_option_button_icon, render_search_mode_button},
- ActivateRegexMode, ActivateSemanticMode, ActivateTextMode, CycleMode, NextHistoryQuery,
- PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions, SelectNextMatch, SelectPrevMatch,
- ToggleCaseSensitive, ToggleReplace, ToggleWholeWord,
++ history::SearchHistory, mode::SearchMode, ActivateRegexMode, ActivateTextMode, CycleMode,
++ NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOptions,
++ SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleReplace, ToggleWholeWord,
};
-use anyhow::{Context, Result};
+use anyhow::{Context as _, Result};
use collections::HashMap;
use editor::{
- items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, MultiBuffer,
- SelectAll, MAX_TAB_TITLE_LEN,
+ items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, EditorEvent,
+ MultiBuffer, SelectAll, MAX_TAB_TITLE_LEN,
};
-use futures::StreamExt;
use gpui::{
- actions,
- elements::*,
- platform::{MouseButton, PromptLevel},
- Action, AnyElement, AnyViewHandle, AppContext, Entity, ModelContext, ModelHandle, Subscription,
- Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
+ actions, div, white, AnyElement, AnyView, AppContext, Context as _, Div, Element, EntityId,
+ EventEmitter, FocusableView, InteractiveElement, IntoElement, KeyContext, Model, ModelContext,
+ ParentElement, PromptLevel, Render, SharedString, Styled, Subscription, Task, View,
+ ViewContext, VisualContext, WeakModel, WeakView, WindowContext,
};
use menu::Confirm;
use project::{
@@@ -41,26 -41,76 +40,31 @@@ use util::{paths::PathMatcher, ResultEx
use workspace::{
item::{BreadcrumbText, Item, ItemEvent, ItemHandle},
searchable::{Direction, SearchableItem, SearchableItemHandle},
- ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace, WorkspaceId,
+ ItemNavHistory, Pane, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
+ WorkspaceId,
};
- actions!(SearchInNew, ToggleFocus, NextField, ToggleFilters,);
+ actions!(
+ project_search,
- [SearchInNew, ToggleFocus, NextField, ToggleFilters,]
++ [SearchInNew, ToggleFocus, NextField, ToggleFilters]
+ );
#[derive(Default)]
-struct ActiveSearches(HashMap<WeakModelHandle<Project>, WeakViewHandle<ProjectSearchView>>);
+struct ActiveSearches(HashMap<WeakModel<Project>, WeakView<ProjectSearchView>>);
#[derive(Default)]
-struct ActiveSettings(HashMap<WeakModelHandle<Project>, ProjectSearchSettings>);
+struct ActiveSettings(HashMap<WeakModel<Project>, ProjectSearchSettings>);
pub fn init(cx: &mut AppContext) {
+ // todo!() po
cx.set_global(ActiveSearches::default());
cx.set_global(ActiveSettings::default());
- cx.add_action(ProjectSearchView::deploy);
- cx.add_action(ProjectSearchView::move_focus_to_results);
- cx.add_action(ProjectSearchBar::confirm);
- cx.add_action(ProjectSearchBar::search_in_new);
- cx.add_action(ProjectSearchBar::select_next_match);
- cx.add_action(ProjectSearchBar::select_prev_match);
- cx.add_action(ProjectSearchBar::replace_next);
- cx.add_action(ProjectSearchBar::replace_all);
- cx.add_action(ProjectSearchBar::cycle_mode);
- cx.add_action(ProjectSearchBar::next_history_query);
- cx.add_action(ProjectSearchBar::previous_history_query);
- cx.add_action(ProjectSearchBar::activate_regex_mode);
- cx.add_action(ProjectSearchBar::toggle_replace);
- cx.add_action(ProjectSearchBar::toggle_replace_on_a_pane);
- cx.add_action(ProjectSearchBar::activate_text_mode);
-
- // This action should only be registered if the semantic index is enabled
- // We are registering it all the time, as I dont want to introduce a dependency
- // for Semantic Index Settings globally whenever search is tested.
- cx.add_action(ProjectSearchBar::activate_semantic_mode);
-
- cx.capture_action(ProjectSearchBar::tab);
- cx.capture_action(ProjectSearchBar::tab_previous);
- cx.capture_action(ProjectSearchView::replace_all);
- cx.capture_action(ProjectSearchView::replace_next);
- add_toggle_option_action::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx);
- add_toggle_option_action::<ToggleWholeWord>(SearchOptions::WHOLE_WORD, cx);
- add_toggle_option_action::<ToggleIncludeIgnored>(SearchOptions::INCLUDE_IGNORED, cx);
- add_toggle_filters_action::<ToggleFilters>(cx);
-}
-
-fn add_toggle_filters_action<A: Action>(cx: &mut AppContext) {
- cx.add_action(move |pane: &mut Pane, _: &A, cx: &mut ViewContext<Pane>| {
- if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<ProjectSearchBar>() {
- if search_bar.update(cx, |search_bar, cx| search_bar.toggle_filters(cx)) {
- return;
- }
- }
- cx.propagate_action();
- });
-}
-
-fn add_toggle_option_action<A: Action>(option: SearchOptions, cx: &mut AppContext) {
- cx.add_action(move |pane: &mut Pane, _: &A, cx: &mut ViewContext<Pane>| {
- if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<ProjectSearchBar>() {
- if search_bar.update(cx, |search_bar, cx| {
- search_bar.toggle_search_option(option, cx)
- }) {
- return;
- }
- }
- cx.propagate_action();
- });
+ cx.observe_new_views(|workspace: &mut Workspace, _cx| {
- workspace.register_action(ProjectSearchView::deploy);
++ workspace
++ .register_action(ProjectSearchView::deploy)
++ .register_action(ProjectSearchBar::search_in_new);
+ })
+ .detach();
}
struct ProjectSearch {
@@@ -1015,24 -1082,10 +1018,10 @@@ impl ProjectSearchView
cx: &mut ViewContext<Workspace>,
) {
// Clean up entries for dropped projects
- cx.update_global(|state: &mut ActiveSearches, cx| {
- state.0.retain(|project, _| project.is_upgradable(cx))
+ cx.update_global(|state: &mut ActiveSearches, _cx| {
+ state.0.retain(|project, _| project.is_upgradable())
});
- let active_search = cx
- .global::<ActiveSearches>()
- .0
- .get(&workspace.project().downgrade())
- .and_then(WeakView::upgrade);
-
- let existing = active_search
- .and_then(|active_search| {
- workspace
- .items_of_type::<ProjectSearchView>(cx)
- .find(|search| search == &active_search)
- })
- .or_else(|| workspace.item_of_type::<ProjectSearchView>(cx));
-
let query = workspace.active_item(cx).and_then(|item| {
let editor = item.act_as::<Editor>(cx)?;
let query = editor.query_suggestion(cx);
@@@ -1043,27 -1096,21 +1032,21 @@@
}
});
- let search = if let Some(existing) = existing {
- workspace.activate_item(&existing, cx);
- existing
- } else {
- let settings = cx
- .global::<ActiveSettings>()
- .0
- .get(&workspace.project().downgrade());
+ let settings = cx
+ .global::<ActiveSettings>()
+ .0
+ .get(&workspace.project().downgrade());
- let settings = if let Some(settings) = settings {
- Some(settings.clone())
- } else {
- None
- };
+ let settings = if let Some(settings) = settings {
+ Some(settings.clone())
+ } else {
+ None
+ };
- let model = cx.build_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
- let view = cx.build_view(|cx| ProjectSearchView::new(model, cx, settings));
- let model = cx.add_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
- let search = cx.add_view(|cx| ProjectSearchView::new(model, cx, settings));
++ let model = cx.build_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
++ let search = cx.build_view(|cx| ProjectSearchView::new(model, cx, settings));
- workspace.add_item(Box::new(view.clone()), cx);
- view
- };
+ workspace.add_item(Box::new(search.clone()), cx);
search.update(cx, |search, cx| {
if let Some(query) = query {