Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,6 @@
"regex": false,
// Whether to center the cursor on each search match when navigating.
"center_on_match": false,
// Whether to search on input in project search.
"search_on_input": false,
// Debounce time in milliseconds for search on input in project search.
// Set to 0 to disable debouncing.
"search_on_input_debounce_ms": 200,
},
// When to populate a new search's query based on the text under the cursor.
// This setting can take the following three values:
Expand Down
7 changes: 0 additions & 7 deletions crates/editor/src/editor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ pub struct SearchSettings {
pub regex: bool,
/// Whether to center the cursor on each search match when navigating.
pub center_on_match: bool,
/// Whether to search on input in project search.
pub search_on_input: bool,
/// Debounce time in milliseconds for search on input in project search.
/// Set to 0 to disable debouncing.
pub search_on_input_debounce_ms: u64,
}

impl EditorSettings {
Expand Down Expand Up @@ -276,8 +271,6 @@ impl Settings for EditorSettings {
include_ignored: search.include_ignored.unwrap(),
regex: search.regex.unwrap(),
center_on_match: search.center_on_match.unwrap(),
search_on_input: search.search_on_input.unwrap(),
search_on_input_debounce_ms: search.search_on_input_debounce_ms.unwrap(),
},
auto_signature_help: editor.auto_signature_help.unwrap(),
show_signature_help_after_edits: editor.show_signature_help_after_edits.unwrap(),
Expand Down
93 changes: 0 additions & 93 deletions crates/search/src/buffer_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3421,8 +3421,6 @@ mod tests {
include_ignored: false,
regex: false,
center_on_match: false,
search_on_input: false,
search_on_input_debounce_ms: 0,
},
cx,
);
Expand Down Expand Up @@ -3486,8 +3484,6 @@ mod tests {
include_ignored: false,
regex: false,
center_on_match: false,
search_on_input: false,
search_on_input_debounce_ms: 0,
},
cx,
);
Expand Down Expand Up @@ -3526,8 +3522,6 @@ mod tests {
include_ignored: false,
regex: false,
center_on_match: false,
search_on_input: false,
search_on_input_debounce_ms: 0,
},
cx,
);
Expand Down Expand Up @@ -3610,96 +3604,9 @@ mod tests {
include_ignored: Some(search_settings.include_ignored),
regex: Some(search_settings.regex),
center_on_match: Some(search_settings.center_on_match),
search_on_input: Some(search_settings.search_on_input),
search_on_input_debounce_ms: Some(
search_settings.search_on_input_debounce_ms,
),
});
});
});
});
}
#[gpui::test]
async fn test_search_on_input_setting(cx: &mut TestAppContext) {
let (editor, search_bar, cx) = init_test(cx);

update_search_settings(
SearchSettings {
button: true,
whole_word: false,
case_sensitive: false,
include_ignored: false,
regex: false,
center_on_match: false,
search_on_input: false,
search_on_input_debounce_ms: 0,
},
cx,
);

search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.show(window, cx);
search_bar.query_editor.update(cx, |query_editor, cx| {
query_editor.buffer().update(cx, |buffer, cx| {
buffer.edit(
[(MultiBufferOffset(0)..MultiBufferOffset(0), "expression")],
None,
cx,
);
});
});
});

cx.background_executor.run_until_parked();

editor.update_in(cx, |editor, window, cx| {
let highlights = editor.all_text_background_highlights(window, cx);
assert!(
highlights.is_empty(),
"No highlights should appear when search_on_input is false"
);
});

update_search_settings(
SearchSettings {
button: true,
whole_word: false,
case_sensitive: false,
include_ignored: false,
regex: false,
center_on_match: false,
search_on_input: true,
search_on_input_debounce_ms: 0,
},
cx,
);

search_bar.update_in(cx, |search_bar, window, cx| {
search_bar.dismiss(&Dismiss, window, cx);
search_bar.show(window, cx);
});

search_bar
.update_in(cx, |search_bar, window, cx| {
search_bar.search("expression", None, true, window, cx)
})
.await
.unwrap();

editor.update_in(cx, |editor, window, cx| {
let highlights = display_points_of(editor.all_text_background_highlights(window, cx));
assert_eq!(
highlights.len(),
2,
"Should find 2 matches for 'expression' when search_on_input is true"
);
assert_eq!(
highlights,
&[
DisplayPoint::new(DisplayRow(0), 10)..DisplayPoint::new(DisplayRow(0), 20),
DisplayPoint::new(DisplayRow(1), 9)..DisplayPoint::new(DisplayRow(1), 19),
]
);
});
}
}
65 changes: 13 additions & 52 deletions crates/search/src/project_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use std::{
ops::{Not, Range},
pin::pin,
sync::Arc,
time::Duration,
};
use ui::{
CommonAnimationExt, IconButtonShape, KeyBinding, Toggleable, Tooltip, prelude::*,
Expand Down Expand Up @@ -271,7 +270,6 @@ pub struct ProjectSearchView {
included_opened_only: bool,
regex_language: Option<Arc<Language>>,
results_collapsed: bool,
current_search_on_input: Task<()>,
_subscriptions: Vec<Subscription>,
}

Expand Down Expand Up @@ -871,43 +869,15 @@ impl ProjectSearchView {
// Subscribe to query_editor in order to reraise editor events for workspace item activation purposes
subscriptions.push(
cx.subscribe(&query_editor, |this, _, event: &EditorEvent, cx| {
if let EditorEvent::Edited { .. } = event {
if EditorSettings::get_global(cx).use_smartcase_search {
let query = this.search_query_text(cx);
if !query.is_empty()
&& this.search_options.contains(SearchOptions::CASE_SENSITIVE)
!= contains_uppercase(&query)
{
this.toggle_search_option(SearchOptions::CASE_SENSITIVE, cx);
}
}

let search_settings = &EditorSettings::get_global(cx).search;
if search_settings.search_on_input {
if this.query_editor.read(cx).is_empty(cx) {
this.current_search_on_input = Task::ready(());
this.entity.update(cx, |model, cx| {
model.pending_search = None;
model.match_ranges.clear();
model.excerpts.update(cx, |excerpts, cx| excerpts.clear(cx));
model.no_results = None;
model.limit_reached = false;
cx.notify();
});
} else {
let debounce = search_settings.search_on_input_debounce_ms;
this.current_search_on_input = cx.spawn(async move |this, cx| {
if debounce > 0 {
cx.background_executor()
.timer(Duration::from_millis(debounce))
.await;
}
this.update(cx, |this, cx| {
this.search(cx);
})
.ok();
});
}
if let EditorEvent::Edited { .. } = event
&& EditorSettings::get_global(cx).use_smartcase_search
{
let query = this.search_query_text(cx);
if !query.is_empty()
&& this.search_options.contains(SearchOptions::CASE_SENSITIVE)
!= contains_uppercase(&query)
{
this.toggle_search_option(SearchOptions::CASE_SENSITIVE, cx);
}
}
cx.emit(ViewEvent::EditorEvent(event.clone()))
Expand Down Expand Up @@ -1028,7 +998,6 @@ impl ProjectSearchView {
included_opened_only: false,
regex_language: None,
results_collapsed: false,
current_search_on_input: Task::ready(()),
_subscriptions: subscriptions,
};

Expand Down Expand Up @@ -1560,11 +1529,7 @@ impl ProjectSearchView {
editor.scroll(Point::default(), Some(Axis::Vertical), window, cx);
}
});
let should_auto_focus = !EditorSettings::get_global(cx).search.search_on_input;
if is_new_search
&& self.query_editor.focus_handle(cx).is_focused(window)
&& should_auto_focus
{
if is_new_search && self.query_editor.focus_handle(cx).is_focused(window) {
self.focus_results_editor(window, cx);
}
}
Expand Down Expand Up @@ -1627,13 +1592,9 @@ impl ProjectSearchView {
v_flex()
.gap_1()
.child(
Label::new(if EditorSettings::get_global(cx).search.search_on_input {
"Start typing to search. For more options:"
} else {
"Hit enter to search. For more options:"
})
.color(Color::Muted)
.mb_2(),
Label::new("Hit enter to search. For more options:")
.color(Color::Muted)
.mb_2(),
)
.child(
Button::new("filter-paths", "Include/exclude specific paths")
Expand Down
8 changes: 0 additions & 8 deletions crates/settings_content/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,14 +828,6 @@ pub struct SearchSettingsContent {
pub regex: Option<bool>,
/// Whether to center the cursor on each search match when navigating.
pub center_on_match: Option<bool>,
/// Whether to search on input in project search.
pub search_on_input: Option<bool>,
/// Debounce time in milliseconds for search on input in project search.
///
/// Set to 0 to disable debouncing.
///
/// Default: 200
pub search_on_input_debounce_ms: Option<u64>,
}

#[with_fallible_options]
Expand Down
48 changes: 1 addition & 47 deletions crates/settings_ui/src/page_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,7 @@ fn languages_and_tools_page(cx: &App) -> SettingsPage {
}

fn search_and_files_page() -> SettingsPage {
fn search_section() -> [SettingsPageItem; 11] {
fn search_section() -> [SettingsPageItem; 9] {
[
SettingsPageItem::SectionHeader("Search"),
SettingsPageItem::SettingItem(SettingItem {
Expand Down Expand Up @@ -3133,52 +3133,6 @@ fn search_and_files_page() -> SettingsPage {
metadata: None,
files: USER,
}),
SettingsPageItem::SettingItem(SettingItem {
title: "Search on Input",
description: "Whether to search on input in project search.",
field: Box::new(SettingField {
json_path: Some("editor.search.search_on_input"),
pick: |settings_content| {
settings_content
.editor
.search
.as_ref()
.and_then(|search| search.search_on_input.as_ref())
},
write: |settings_content, value| {
settings_content
.editor
.search
.get_or_insert_default()
.search_on_input = value;
},
}),
metadata: None,
files: USER,
}),
SettingsPageItem::SettingItem(SettingItem {
title: "Search on Input Debounce",
description: "Debounce time in milliseconds for search on input (set to 0 to disable debouncing).",
field: Box::new(SettingField {
json_path: Some("editor.search.search_on_input_debounce_ms"),
pick: |settings_content| {
settings_content
.editor
.search
.as_ref()
.and_then(|search| search.search_on_input_debounce_ms.as_ref())
},
write: |settings_content, value| {
settings_content
.editor
.search
.get_or_insert_default()
.search_on_input_debounce_ms = value;
},
}),
metadata: None,
files: USER,
}),
SettingsPageItem::SettingItem(SettingItem {
title: "Seed Search Query From Cursor",
description: "When to populate a new search's query based on the text under the cursor.",
Expand Down
18 changes: 6 additions & 12 deletions docs/src/reference/all-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -3270,18 +3270,6 @@ Non-negative `integer` values
- Setting: `regex`
- Default: `false`

### Search On Input

- Description: Whether to search on input in project search.
- Setting: `search_on_input`
- Default: `false`

### Search On Input Debounce Ms

- Description: Debounce time in milliseconds for search on input in project search. Set to 0 to disable debouncing.
- Setting: `search_on_input_debounce_ms`
- Default: `200`

### Center On Match

- Description: Whether to center the cursor on each search match when navigating.
Expand All @@ -3294,6 +3282,12 @@ Non-negative `integer` values
- Setting: `search_wrap`
- Default: `true`

## Center on Match

- Description: If `center_on_match` is enabled, the editor will center the cursor on the current match when searching.
- Setting: `center_on_match`
- Default: `false`

## Seed Search Query From Cursor

- Description: When to populate a new search's query based on the text under the cursor.
Expand Down