mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
WIP: start search2
This commit is contained in:
parent
7a454bed22
commit
dfd68d4cb8
30
Cargo.lock
generated
30
Cargo.lock
generated
@ -7855,6 +7855,35 @@ dependencies = [
|
|||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "search2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"client2",
|
||||||
|
"collections",
|
||||||
|
"editor2",
|
||||||
|
"futures 0.3.28",
|
||||||
|
"gpui2",
|
||||||
|
"language2",
|
||||||
|
"log",
|
||||||
|
"menu2",
|
||||||
|
"postage",
|
||||||
|
"project2",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"settings2",
|
||||||
|
"smallvec",
|
||||||
|
"smol",
|
||||||
|
"theme2",
|
||||||
|
"ui2",
|
||||||
|
"unindent",
|
||||||
|
"util",
|
||||||
|
"workspace2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework"
|
name = "security-framework"
|
||||||
version = "2.9.2"
|
version = "2.9.2"
|
||||||
@ -11425,6 +11454,7 @@ dependencies = [
|
|||||||
"rsa 0.4.0",
|
"rsa 0.4.0",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"schemars",
|
"schemars",
|
||||||
|
"search2",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -86,6 +86,7 @@ members = [
|
|||||||
"crates/rpc",
|
"crates/rpc",
|
||||||
"crates/rpc2",
|
"crates/rpc2",
|
||||||
"crates/search",
|
"crates/search",
|
||||||
|
"crates/search2",
|
||||||
"crates/settings",
|
"crates/settings",
|
||||||
"crates/settings2",
|
"crates/settings2",
|
||||||
"crates/snippet",
|
"crates/snippet",
|
||||||
|
@ -906,17 +906,16 @@ impl SearchableItem for Editor {
|
|||||||
type Match = Range<Anchor>;
|
type Match = Range<Anchor>;
|
||||||
|
|
||||||
fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
|
fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
todo!()
|
self.clear_background_highlights::<BufferSearchHighlights>(cx);
|
||||||
// self.clear_background_highlights::<BufferSearchHighlights>(cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_matches(&mut self, matches: Vec<Range<Anchor>>, cx: &mut ViewContext<Self>) {
|
fn update_matches(&mut self, matches: Vec<Range<Anchor>>, cx: &mut ViewContext<Self>) {
|
||||||
todo!()
|
dbg!(&matches);
|
||||||
// self.highlight_background::<BufferSearchHighlights>(
|
self.highlight_background::<BufferSearchHighlights>(
|
||||||
// matches,
|
matches,
|
||||||
// |theme| theme.search.match_background,
|
|theme| theme.title_bar_background, // todo: update theme
|
||||||
// cx,
|
cx,
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String {
|
fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String {
|
||||||
@ -951,22 +950,20 @@ impl SearchableItem for Editor {
|
|||||||
matches: Vec<Range<Anchor>>,
|
matches: Vec<Range<Anchor>>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
todo!()
|
self.unfold_ranges([matches[index].clone()], false, true, cx);
|
||||||
// self.unfold_ranges([matches[index].clone()], false, true, cx);
|
let range = self.range_for_match(&matches[index]);
|
||||||
// let range = self.range_for_match(&matches[index]);
|
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
// self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
s.select_ranges([range]);
|
||||||
// s.select_ranges([range]);
|
})
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
|
fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
|
||||||
todo!()
|
self.unfold_ranges(matches.clone(), false, false, cx);
|
||||||
// self.unfold_ranges(matches.clone(), false, false, cx);
|
let mut ranges = Vec::new();
|
||||||
// let mut ranges = Vec::new();
|
for m in &matches {
|
||||||
// for m in &matches {
|
ranges.push(self.range_for_match(&m))
|
||||||
// ranges.push(self.range_for_match(&m))
|
}
|
||||||
// }
|
self.change_selections(None, cx, |s| s.select_ranges(ranges));
|
||||||
// self.change_selections(None, cx, |s| s.select_ranges(ranges));
|
|
||||||
}
|
}
|
||||||
fn replace(
|
fn replace(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
40
crates/search2/Cargo.toml
Normal file
40
crates/search2/Cargo.toml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[package]
|
||||||
|
name = "search2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/search.rs"
|
||||||
|
doctest = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bitflags = "1"
|
||||||
|
collections = { path = "../collections" }
|
||||||
|
editor = { package = "editor2", path = "../editor2" }
|
||||||
|
gpui = { package = "gpui2", path = "../gpui2" }
|
||||||
|
language = { package = "language2", path = "../language2" }
|
||||||
|
menu = { package = "menu2", path = "../menu2" }
|
||||||
|
project = { package = "project2", path = "../project2" }
|
||||||
|
settings = { package = "settings2", path = "../settings2" }
|
||||||
|
theme = { package = "theme2", path = "../theme2" }
|
||||||
|
util = { path = "../util" }
|
||||||
|
ui = {package = "ui2", path = "../ui2"}
|
||||||
|
workspace = { package = "workspace2", path = "../workspace2" }
|
||||||
|
#semantic_index = { path = "../semantic_index" }
|
||||||
|
anyhow.workspace = true
|
||||||
|
futures.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
postage.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
|
serde_derive.workspace = true
|
||||||
|
smallvec.workspace = true
|
||||||
|
smol.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
[dev-dependencies]
|
||||||
|
client = { package = "client2", path = "../client2", features = ["test-support"] }
|
||||||
|
editor = { package = "editor2", path = "../editor2", features = ["test-support"] }
|
||||||
|
gpui = { package = "gpui2", path = "../gpui2", features = ["test-support"] }
|
||||||
|
|
||||||
|
workspace = { package = "workspace2", path = "../workspace2", features = ["test-support"] }
|
||||||
|
unindent.workspace = true
|
1797
crates/search2/src/buffer_search.rs
Normal file
1797
crates/search2/src/buffer_search.rs
Normal file
File diff suppressed because it is too large
Load Diff
184
crates/search2/src/history.rs
Normal file
184
crates/search2/src/history.rs
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
use smallvec::SmallVec;
|
||||||
|
const SEARCH_HISTORY_LIMIT: usize = 20;
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone)]
|
||||||
|
pub struct SearchHistory {
|
||||||
|
history: SmallVec<[String; SEARCH_HISTORY_LIMIT]>,
|
||||||
|
selected: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SearchHistory {
|
||||||
|
pub fn add(&mut self, search_string: String) {
|
||||||
|
if let Some(i) = self.selected {
|
||||||
|
if search_string == self.history[i] {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(previously_searched) = self.history.last_mut() {
|
||||||
|
if search_string.find(previously_searched.as_str()).is_some() {
|
||||||
|
*previously_searched = search_string;
|
||||||
|
self.selected = Some(self.history.len() - 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.history.push(search_string);
|
||||||
|
if self.history.len() > SEARCH_HISTORY_LIMIT {
|
||||||
|
self.history.remove(0);
|
||||||
|
}
|
||||||
|
self.selected = Some(self.history.len() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next(&mut self) -> Option<&str> {
|
||||||
|
let history_size = self.history.len();
|
||||||
|
if history_size == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let selected = self.selected?;
|
||||||
|
if selected == history_size - 1 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let next_index = selected + 1;
|
||||||
|
self.selected = Some(next_index);
|
||||||
|
Some(&self.history[next_index])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current(&self) -> Option<&str> {
|
||||||
|
Some(&self.history[self.selected?])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn previous(&mut self) -> Option<&str> {
|
||||||
|
let history_size = self.history.len();
|
||||||
|
if history_size == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let prev_index = match self.selected {
|
||||||
|
Some(selected_index) => {
|
||||||
|
if selected_index == 0 {
|
||||||
|
return None;
|
||||||
|
} else {
|
||||||
|
selected_index - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => history_size - 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.selected = Some(prev_index);
|
||||||
|
Some(&self.history[prev_index])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_selection(&mut self) {
|
||||||
|
self.selected = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add() {
|
||||||
|
let mut search_history = SearchHistory::default();
|
||||||
|
assert_eq!(
|
||||||
|
search_history.current(),
|
||||||
|
None,
|
||||||
|
"No current selection should be set fo the default search history"
|
||||||
|
);
|
||||||
|
|
||||||
|
search_history.add("rust".to_string());
|
||||||
|
assert_eq!(
|
||||||
|
search_history.current(),
|
||||||
|
Some("rust"),
|
||||||
|
"Newly added item should be selected"
|
||||||
|
);
|
||||||
|
|
||||||
|
// check if duplicates are not added
|
||||||
|
search_history.add("rust".to_string());
|
||||||
|
assert_eq!(
|
||||||
|
search_history.history.len(),
|
||||||
|
1,
|
||||||
|
"Should not add a duplicate"
|
||||||
|
);
|
||||||
|
assert_eq!(search_history.current(), Some("rust"));
|
||||||
|
|
||||||
|
// check if new string containing the previous string replaces it
|
||||||
|
search_history.add("rustlang".to_string());
|
||||||
|
assert_eq!(
|
||||||
|
search_history.history.len(),
|
||||||
|
1,
|
||||||
|
"Should replace previous item if it's a substring"
|
||||||
|
);
|
||||||
|
assert_eq!(search_history.current(), Some("rustlang"));
|
||||||
|
|
||||||
|
// push enough items to test SEARCH_HISTORY_LIMIT
|
||||||
|
for i in 0..SEARCH_HISTORY_LIMIT * 2 {
|
||||||
|
search_history.add(format!("item{i}"));
|
||||||
|
}
|
||||||
|
assert!(search_history.history.len() <= SEARCH_HISTORY_LIMIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_next_and_previous() {
|
||||||
|
let mut search_history = SearchHistory::default();
|
||||||
|
assert_eq!(
|
||||||
|
search_history.next(),
|
||||||
|
None,
|
||||||
|
"Default search history should not have a next item"
|
||||||
|
);
|
||||||
|
|
||||||
|
search_history.add("Rust".to_string());
|
||||||
|
assert_eq!(search_history.next(), None);
|
||||||
|
search_history.add("JavaScript".to_string());
|
||||||
|
assert_eq!(search_history.next(), None);
|
||||||
|
search_history.add("TypeScript".to_string());
|
||||||
|
assert_eq!(search_history.next(), None);
|
||||||
|
|
||||||
|
assert_eq!(search_history.current(), Some("TypeScript"));
|
||||||
|
|
||||||
|
assert_eq!(search_history.previous(), Some("JavaScript"));
|
||||||
|
assert_eq!(search_history.current(), Some("JavaScript"));
|
||||||
|
|
||||||
|
assert_eq!(search_history.previous(), Some("Rust"));
|
||||||
|
assert_eq!(search_history.current(), Some("Rust"));
|
||||||
|
|
||||||
|
assert_eq!(search_history.previous(), None);
|
||||||
|
assert_eq!(search_history.current(), Some("Rust"));
|
||||||
|
|
||||||
|
assert_eq!(search_history.next(), Some("JavaScript"));
|
||||||
|
assert_eq!(search_history.current(), Some("JavaScript"));
|
||||||
|
|
||||||
|
assert_eq!(search_history.next(), Some("TypeScript"));
|
||||||
|
assert_eq!(search_history.current(), Some("TypeScript"));
|
||||||
|
|
||||||
|
assert_eq!(search_history.next(), None);
|
||||||
|
assert_eq!(search_history.current(), Some("TypeScript"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_reset_selection() {
|
||||||
|
let mut search_history = SearchHistory::default();
|
||||||
|
search_history.add("Rust".to_string());
|
||||||
|
search_history.add("JavaScript".to_string());
|
||||||
|
search_history.add("TypeScript".to_string());
|
||||||
|
|
||||||
|
assert_eq!(search_history.current(), Some("TypeScript"));
|
||||||
|
search_history.reset_selection();
|
||||||
|
assert_eq!(search_history.current(), None);
|
||||||
|
assert_eq!(
|
||||||
|
search_history.previous(),
|
||||||
|
Some("TypeScript"),
|
||||||
|
"Should start from the end after reset on previous item query"
|
||||||
|
);
|
||||||
|
|
||||||
|
search_history.previous();
|
||||||
|
assert_eq!(search_history.current(), Some("JavaScript"));
|
||||||
|
search_history.previous();
|
||||||
|
assert_eq!(search_history.current(), Some("Rust"));
|
||||||
|
|
||||||
|
search_history.reset_selection();
|
||||||
|
assert_eq!(search_history.current(), None);
|
||||||
|
}
|
||||||
|
}
|
65
crates/search2/src/mode.rs
Normal file
65
crates/search2/src/mode.rs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
use gpui::Action;
|
||||||
|
|
||||||
|
use crate::{ActivateRegexMode, ActivateSemanticMode, ActivateTextMode};
|
||||||
|
// TODO: Update the default search mode to get from config
|
||||||
|
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||||
|
pub enum SearchMode {
|
||||||
|
#[default]
|
||||||
|
Text,
|
||||||
|
Semantic,
|
||||||
|
Regex,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
|
pub(crate) enum Side {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SearchMode {
|
||||||
|
pub(crate) fn label(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
SearchMode::Text => "Text",
|
||||||
|
SearchMode::Semantic => "Semantic",
|
||||||
|
SearchMode::Regex => "Regex",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn region_id(&self) -> usize {
|
||||||
|
match self {
|
||||||
|
SearchMode::Text => 3,
|
||||||
|
SearchMode::Semantic => 4,
|
||||||
|
SearchMode::Regex => 5,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn tooltip_text(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
SearchMode::Text => "Activate Text Search",
|
||||||
|
SearchMode::Semantic => "Activate Semantic Search",
|
||||||
|
SearchMode::Regex => "Activate Regex Search",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn activate_action(&self) -> Box<dyn Action> {
|
||||||
|
match self {
|
||||||
|
SearchMode::Text => Box::new(ActivateTextMode),
|
||||||
|
SearchMode::Semantic => Box::new(ActivateSemanticMode),
|
||||||
|
SearchMode::Regex => Box::new(ActivateRegexMode),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn next_mode(mode: &SearchMode, semantic_enabled: bool) -> SearchMode {
|
||||||
|
match mode {
|
||||||
|
SearchMode::Text => SearchMode::Regex,
|
||||||
|
SearchMode::Regex => {
|
||||||
|
if semantic_enabled {
|
||||||
|
SearchMode::Semantic
|
||||||
|
} else {
|
||||||
|
SearchMode::Text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SearchMode::Semantic => SearchMode::Text,
|
||||||
|
}
|
||||||
|
}
|
2661
crates/search2/src/project_search.rs
Normal file
2661
crates/search2/src/project_search.rs
Normal file
File diff suppressed because it is too large
Load Diff
115
crates/search2/src/search.rs
Normal file
115
crates/search2/src/search.rs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
use bitflags::bitflags;
|
||||||
|
pub use buffer_search::BufferSearchBar;
|
||||||
|
use gpui::{actions, Action, AnyElement, AppContext, Component, Element, Svg, View};
|
||||||
|
pub use mode::SearchMode;
|
||||||
|
use project::search::SearchQuery;
|
||||||
|
use ui::ButtonVariant;
|
||||||
|
//pub use project_search::{ProjectSearchBar, ProjectSearchView};
|
||||||
|
// use theme::components::{
|
||||||
|
// action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle,
|
||||||
|
// };
|
||||||
|
|
||||||
|
pub mod buffer_search;
|
||||||
|
mod history;
|
||||||
|
mod mode;
|
||||||
|
//pub mod project_search;
|
||||||
|
pub(crate) mod search_bar;
|
||||||
|
|
||||||
|
pub fn init(cx: &mut AppContext) {
|
||||||
|
buffer_search::init(cx);
|
||||||
|
//project_search::init(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
actions!(
|
||||||
|
CycleMode,
|
||||||
|
ToggleWholeWord,
|
||||||
|
ToggleCaseSensitive,
|
||||||
|
ToggleReplace,
|
||||||
|
SelectNextMatch,
|
||||||
|
SelectPrevMatch,
|
||||||
|
SelectAllMatches,
|
||||||
|
NextHistoryQuery,
|
||||||
|
PreviousHistoryQuery,
|
||||||
|
ActivateTextMode,
|
||||||
|
ActivateSemanticMode,
|
||||||
|
ActivateRegexMode,
|
||||||
|
ReplaceAll,
|
||||||
|
ReplaceNext,
|
||||||
|
);
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct SearchOptions: u8 {
|
||||||
|
const NONE = 0b000;
|
||||||
|
const WHOLE_WORD = 0b001;
|
||||||
|
const CASE_SENSITIVE = 0b010;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SearchOptions {
|
||||||
|
pub fn label(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
SearchOptions::WHOLE_WORD => "Match Whole Word",
|
||||||
|
SearchOptions::CASE_SENSITIVE => "Match Case",
|
||||||
|
_ => panic!("{:?} is not a named SearchOption", self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn icon(&self) -> ui::Icon {
|
||||||
|
match *self {
|
||||||
|
SearchOptions::WHOLE_WORD => ui::Icon::WholeWord,
|
||||||
|
SearchOptions::CASE_SENSITIVE => ui::Icon::CaseSensitive,
|
||||||
|
_ => panic!("{:?} is not a named SearchOption", self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_toggle_action(&self) -> Box<dyn Action + Sync + Send + 'static> {
|
||||||
|
match *self {
|
||||||
|
SearchOptions::WHOLE_WORD => Box::new(ToggleWholeWord),
|
||||||
|
SearchOptions::CASE_SENSITIVE => Box::new(ToggleCaseSensitive),
|
||||||
|
_ => panic!("{:?} is not a named SearchOption", self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn none() -> SearchOptions {
|
||||||
|
SearchOptions::NONE
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_query(query: &SearchQuery) -> SearchOptions {
|
||||||
|
let mut options = SearchOptions::NONE;
|
||||||
|
options.set(SearchOptions::WHOLE_WORD, query.whole_word());
|
||||||
|
options.set(SearchOptions::CASE_SENSITIVE, query.case_sensitive());
|
||||||
|
options
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_button<V: 'static>(&self, active: bool) -> impl Component<V> {
|
||||||
|
ui::IconButton::new(0, self.icon())
|
||||||
|
.on_click({
|
||||||
|
let action = self.to_toggle_action();
|
||||||
|
move |_: &mut V, cx| {
|
||||||
|
cx.dispatch_action(action.boxed_clone());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.variant(ui::ButtonVariant::Ghost)
|
||||||
|
.when(active, |button| button.variant(ButtonVariant::Filled))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_replace_button<V: 'static>(active: bool) -> impl Component<V> {
|
||||||
|
// todo: add toggle_replace button
|
||||||
|
ui::IconButton::new(0, ui::Icon::Replace)
|
||||||
|
.on_click(|_: &mut V, cx| {
|
||||||
|
cx.dispatch_action(Box::new(ToggleReplace));
|
||||||
|
})
|
||||||
|
.variant(ui::ButtonVariant::Ghost)
|
||||||
|
.when(active, |button| button.variant(ButtonVariant::Filled))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_action<V: 'static>(
|
||||||
|
action: impl Action + 'static + Send + Sync,
|
||||||
|
name: &'static str,
|
||||||
|
) -> impl Component<V> {
|
||||||
|
ui::IconButton::new(0, ui::Icon::Replace).on_click(move |_: &mut V, cx| {
|
||||||
|
cx.dispatch_action(action.boxed_clone());
|
||||||
|
})
|
||||||
|
}
|
177
crates/search2/src/search_bar.rs
Normal file
177
crates/search2/src/search_bar.rs
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use gpui::{
|
||||||
|
div, Action, AnyElement, Component, CursorStyle, Element, MouseButton, MouseDownEvent, Svg,
|
||||||
|
View, ViewContext,
|
||||||
|
};
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::Label;
|
||||||
|
use workspace::searchable::Direction;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
mode::{SearchMode, Side},
|
||||||
|
SelectNextMatch, SelectPrevMatch,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(super) fn render_nav_button<V: 'static>(
|
||||||
|
icon: &'static str,
|
||||||
|
direction: Direction,
|
||||||
|
active: bool,
|
||||||
|
on_click: impl Fn(MouseDownEvent, &mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
cx: &mut ViewContext<V>,
|
||||||
|
) -> impl Component<V> {
|
||||||
|
let action: Box<dyn Action>;
|
||||||
|
let tooltip;
|
||||||
|
|
||||||
|
match direction {
|
||||||
|
Direction::Prev => {
|
||||||
|
action = Box::new(SelectPrevMatch);
|
||||||
|
tooltip = "Select Previous Match";
|
||||||
|
}
|
||||||
|
Direction::Next => {
|
||||||
|
action = Box::new(SelectNextMatch);
|
||||||
|
tooltip = "Select Next Match";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// let tooltip_style = cx.theme().tooltip.clone();
|
||||||
|
// let cursor_style = if active {
|
||||||
|
// CursorStyle::PointingHand
|
||||||
|
// } else {
|
||||||
|
// CursorStyle::default()
|
||||||
|
// };
|
||||||
|
// enum NavButton {}
|
||||||
|
div()
|
||||||
|
// 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(MouseClick, &mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
cx: &mut ViewContext<V>,
|
||||||
|
) -> impl Component<V> {
|
||||||
|
//let tooltip_style = cx.theme().tooltip.clone();
|
||||||
|
enum SearchModeButton {}
|
||||||
|
div()
|
||||||
|
// 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>(
|
||||||
|
is_active: bool,
|
||||||
|
icon: &'static str,
|
||||||
|
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()
|
||||||
|
// MouseEventHandler::new::<V, _>(id, cx, |state, cx| {
|
||||||
|
// let theme = cx.theme();
|
||||||
|
// let style = theme
|
||||||
|
// .search
|
||||||
|
// .option_button
|
||||||
|
// .in_state(is_active)
|
||||||
|
// .style_for(state);
|
||||||
|
// Svg::new(icon)
|
||||||
|
// .with_color(style.color.clone())
|
||||||
|
// .constrained()
|
||||||
|
// .with_width(style.icon_width)
|
||||||
|
// .contained()
|
||||||
|
// .with_style(style.container)
|
||||||
|
// .constrained()
|
||||||
|
// .with_height(theme.search.option_button_height)
|
||||||
|
// .with_width(style.button_width)
|
||||||
|
// })
|
||||||
|
// .on_click(MouseButton::Left, on_click)
|
||||||
|
// .with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
// .with_tooltip::<V>(id, label, Some(action), tooltip_style, cx)
|
||||||
|
// .into_any()
|
||||||
|
}
|
@ -97,6 +97,8 @@ pub enum Icon {
|
|||||||
BellRing,
|
BellRing,
|
||||||
MailOpen,
|
MailOpen,
|
||||||
AtSign,
|
AtSign,
|
||||||
|
WholeWord,
|
||||||
|
CaseSensitive,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Icon {
|
impl Icon {
|
||||||
@ -155,6 +157,8 @@ impl Icon {
|
|||||||
Icon::BellRing => "icons/bell-ring.svg",
|
Icon::BellRing => "icons/bell-ring.svg",
|
||||||
Icon::MailOpen => "icons/mail-open.svg",
|
Icon::MailOpen => "icons/mail-open.svg",
|
||||||
Icon::AtSign => "icons/at-sign.svg",
|
Icon::AtSign => "icons/at-sign.svg",
|
||||||
|
Icon::WholeWord => "icons/word_search.svg",
|
||||||
|
Icon::CaseSensitive => "icons/case_insensitive.svg",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1909,7 +1909,7 @@ impl Render for Pane {
|
|||||||
v_stack()
|
v_stack()
|
||||||
.size_full()
|
.size_full()
|
||||||
.child(self.render_tab_bar(cx))
|
.child(self.render_tab_bar(cx))
|
||||||
.child(div() /* todo!(toolbar) */)
|
.child(self.toolbar.clone())
|
||||||
.child(if let Some(item) = self.active_item() {
|
.child(if let Some(item) = self.active_item() {
|
||||||
div().flex_1().child(item.to_any())
|
div().flex_1().child(item.to_any())
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use std::{any::Any, sync::Arc};
|
use std::{any::Any, sync::Arc};
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WindowContext,
|
AnyView, AppContext, EventEmitter, Subscription, Task, View, ViewContext, WeakView,
|
||||||
|
WindowContext,
|
||||||
};
|
};
|
||||||
use project2::search::SearchQuery;
|
use project2::search::SearchQuery;
|
||||||
|
|
||||||
@ -129,8 +130,7 @@ pub trait SearchableItemHandle: ItemHandle {
|
|||||||
// todo!("here is where we need to use AnyWeakView");
|
// todo!("here is where we need to use AnyWeakView");
|
||||||
impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
impl<T: SearchableItem> SearchableItemHandle for View<T> {
|
||||||
fn downgrade(&self) -> Box<dyn WeakSearchableItemHandle> {
|
fn downgrade(&self) -> Box<dyn WeakSearchableItemHandle> {
|
||||||
// Box::new(self.downgrade())
|
Box::new(self.downgrade())
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn boxed_clone(&self) -> Box<dyn SearchableItemHandle> {
|
fn boxed_clone(&self) -> Box<dyn SearchableItemHandle> {
|
||||||
@ -252,16 +252,15 @@ pub trait WeakSearchableItemHandle: WeakItemHandle {
|
|||||||
// fn into_any(self) -> AnyWeakView;
|
// fn into_any(self) -> AnyWeakView;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo!()
|
impl<T: SearchableItem> WeakSearchableItemHandle for WeakView<T> {
|
||||||
// impl<T: SearchableItem> WeakSearchableItemHandle for WeakView<T> {
|
fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>> {
|
||||||
// fn upgrade(&self, cx: &AppContext) -> Option<Box<dyn SearchableItemHandle>> {
|
Some(Box::new(self.upgrade()?))
|
||||||
// Some(Box::new(self.upgrade(cx)?))
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// // fn into_any(self) -> AnyView {
|
// fn into_any(self) -> AnyView {
|
||||||
// // self.into_any()
|
// self.into_any()
|
||||||
// // }
|
// }
|
||||||
// }
|
}
|
||||||
|
|
||||||
impl PartialEq for Box<dyn WeakSearchableItemHandle> {
|
impl PartialEq for Box<dyn WeakSearchableItemHandle> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::ItemHandle;
|
use crate::ItemHandle;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyView, Div, Entity, EntityId, EventEmitter, Render, View, ViewContext, WindowContext,
|
div, AnyView, Div, Entity, EntityId, EventEmitter, ParentElement, Render, View, ViewContext,
|
||||||
|
WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum ToolbarItemEvent {
|
pub enum ToolbarItemEvent {
|
||||||
@ -55,7 +56,8 @@ impl Render for Toolbar {
|
|||||||
type Element = Div<Self>;
|
type Element = Div<Self>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
todo!()
|
//dbg!(&self.items.len());
|
||||||
|
div().children(self.items.iter().map(|(child, _)| child.to_any()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use theme2::ActiveTheme;
|
use theme2::ActiveTheme;
|
||||||
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
pub use toolbar::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView};
|
||||||
use ui::{h_stack, Label};
|
use ui::{h_stack, Label};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -37,7 +37,7 @@ db = { package = "db2", path = "../db2" }
|
|||||||
editor = { package="editor2", path = "../editor2" }
|
editor = { package="editor2", path = "../editor2" }
|
||||||
# feedback = { path = "../feedback" }
|
# feedback = { path = "../feedback" }
|
||||||
# file_finder = { path = "../file_finder" }
|
# file_finder = { path = "../file_finder" }
|
||||||
# search = { path = "../search" }
|
search = { package = "search2", path = "../search2" }
|
||||||
fs = { package = "fs2", path = "../fs2" }
|
fs = { package = "fs2", path = "../fs2" }
|
||||||
fsevent = { path = "../fsevent" }
|
fsevent = { path = "../fsevent" }
|
||||||
fuzzy = { path = "../fuzzy" }
|
fuzzy = { path = "../fuzzy" }
|
||||||
|
@ -194,7 +194,7 @@ fn main() {
|
|||||||
// project_panel::init(Assets, cx);
|
// project_panel::init(Assets, cx);
|
||||||
// channel::init(&client, user_store.clone(), cx);
|
// channel::init(&client, user_store.clone(), cx);
|
||||||
// diagnostics::init(cx);
|
// diagnostics::init(cx);
|
||||||
// search::init(cx);
|
search::init(cx);
|
||||||
// semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
|
// semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
|
||||||
// vim::init(cx);
|
// vim::init(cx);
|
||||||
// terminal_view::init(cx);
|
// terminal_view::init(cx);
|
||||||
|
@ -8,8 +8,8 @@ mod open_listener;
|
|||||||
|
|
||||||
pub use assets::*;
|
pub use assets::*;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
point, px, AppContext, AsyncWindowContext, Task, TitlebarOptions, WeakView, WindowBounds,
|
point, px, AppContext, AsyncWindowContext, Task, TitlebarOptions, VisualContext as _, WeakView,
|
||||||
WindowKind, WindowOptions,
|
WindowBounds, WindowKind, WindowOptions,
|
||||||
};
|
};
|
||||||
pub use only_instance::*;
|
pub use only_instance::*;
|
||||||
pub use open_listener::*;
|
pub use open_listener::*;
|
||||||
@ -64,8 +64,8 @@ pub fn initialize_workspace(
|
|||||||
// todo!()
|
// todo!()
|
||||||
// let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
|
// let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
|
||||||
// toolbar.add_item(breadcrumbs, cx);
|
// toolbar.add_item(breadcrumbs, cx);
|
||||||
// let buffer_search_bar = cx.add_view(BufferSearchBar::new);
|
let buffer_search_bar = cx.build_view(search::BufferSearchBar::new);
|
||||||
// toolbar.add_item(buffer_search_bar.clone(), cx);
|
toolbar.add_item(buffer_search_bar.clone(), cx);
|
||||||
// let quick_action_bar = cx.add_view(|_| {
|
// let quick_action_bar = cx.add_view(|_| {
|
||||||
// QuickActionBar::new(buffer_search_bar, workspace)
|
// QuickActionBar::new(buffer_search_bar, workspace)
|
||||||
// });
|
// });
|
||||||
|
Loading…
Reference in New Issue
Block a user