Auto-fix clippy::collapsible_if violations (#36428)
Release Notes: - N/A
This commit is contained in:
parent
9e8ec72bd5
commit
8f567383e4
281 changed files with 6628 additions and 7089 deletions
|
@ -794,15 +794,13 @@ impl BufferSearchBar {
|
|||
}
|
||||
|
||||
pub fn activate_current_match(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(match_ix) = self.active_match_index {
|
||||
if let Some(active_searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&active_searchable_item.downgrade())
|
||||
{
|
||||
active_searchable_item.activate_match(match_ix, matches, window, cx)
|
||||
}
|
||||
}
|
||||
if let Some(match_ix) = self.active_match_index
|
||||
&& let Some(active_searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&active_searchable_item.downgrade())
|
||||
{
|
||||
active_searchable_item.activate_match(match_ix, matches, window, cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -951,16 +949,15 @@ impl BufferSearchBar {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if !self.dismissed && self.active_match_index.is_some() {
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
searchable_item.select_matches(matches, window, cx);
|
||||
self.focus_editor(&FocusEditor, window, cx);
|
||||
}
|
||||
}
|
||||
if !self.dismissed
|
||||
&& self.active_match_index.is_some()
|
||||
&& let Some(searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
searchable_item.select_matches(matches, window, cx);
|
||||
self.focus_editor(&FocusEditor, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -971,59 +968,55 @@ impl BufferSearchBar {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if let Some(index) = self.active_match_index {
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
.filter(|matches| !matches.is_empty())
|
||||
{
|
||||
// If 'wrapscan' is disabled, searches do not wrap around the end of the file.
|
||||
if !EditorSettings::get_global(cx).search_wrap
|
||||
&& ((direction == Direction::Next && index + count >= matches.len())
|
||||
|| (direction == Direction::Prev && index < count))
|
||||
{
|
||||
crate::show_no_more_matches(window, cx);
|
||||
return;
|
||||
}
|
||||
let new_match_index = searchable_item
|
||||
.match_index_for_direction(matches, index, direction, count, window, cx);
|
||||
|
||||
searchable_item.update_matches(matches, window, cx);
|
||||
searchable_item.activate_match(new_match_index, matches, window, cx);
|
||||
}
|
||||
if let Some(index) = self.active_match_index
|
||||
&& let Some(searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
.filter(|matches| !matches.is_empty())
|
||||
{
|
||||
// If 'wrapscan' is disabled, searches do not wrap around the end of the file.
|
||||
if !EditorSettings::get_global(cx).search_wrap
|
||||
&& ((direction == Direction::Next && index + count >= matches.len())
|
||||
|| (direction == Direction::Prev && index < count))
|
||||
{
|
||||
crate::show_no_more_matches(window, cx);
|
||||
return;
|
||||
}
|
||||
let new_match_index = searchable_item
|
||||
.match_index_for_direction(matches, index, direction, count, window, cx);
|
||||
|
||||
searchable_item.update_matches(matches, window, cx);
|
||||
searchable_item.activate_match(new_match_index, matches, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_first_match(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(matches) = self
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
if matches.is_empty() {
|
||||
return;
|
||||
}
|
||||
searchable_item.update_matches(matches, window, cx);
|
||||
searchable_item.activate_match(0, matches, window, cx);
|
||||
{
|
||||
if matches.is_empty() {
|
||||
return;
|
||||
}
|
||||
searchable_item.update_matches(matches, window, cx);
|
||||
searchable_item.activate_match(0, matches, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_last_match(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(matches) = self
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
if matches.is_empty() {
|
||||
return;
|
||||
}
|
||||
let new_match_index = matches.len() - 1;
|
||||
searchable_item.update_matches(matches, window, cx);
|
||||
searchable_item.activate_match(new_match_index, matches, window, cx);
|
||||
{
|
||||
if matches.is_empty() {
|
||||
return;
|
||||
}
|
||||
let new_match_index = matches.len() - 1;
|
||||
searchable_item.update_matches(matches, window, cx);
|
||||
searchable_item.activate_match(new_match_index, matches, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1344,15 +1337,14 @@ impl BufferSearchBar {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.query(cx).is_empty() {
|
||||
if let Some(new_query) = self
|
||||
if self.query(cx).is_empty()
|
||||
&& let Some(new_query) = self
|
||||
.search_history
|
||||
.current(&mut self.search_history_cursor)
|
||||
.map(str::to_string)
|
||||
{
|
||||
drop(self.search(&new_query, Some(self.search_options), window, cx));
|
||||
return;
|
||||
}
|
||||
{
|
||||
drop(self.search(&new_query, Some(self.search_options), window, cx));
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(new_query) = self
|
||||
|
@ -1384,25 +1376,23 @@ impl BufferSearchBar {
|
|||
|
||||
fn replace_next(&mut self, _: &ReplaceNext, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let mut should_propagate = true;
|
||||
if !self.dismissed && self.active_search.is_some() {
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(query) = self.active_search.as_ref() {
|
||||
if let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
if let Some(active_index) = self.active_match_index {
|
||||
let query = query
|
||||
.as_ref()
|
||||
.clone()
|
||||
.with_replacement(self.replacement(cx));
|
||||
searchable_item.replace(matches.at(active_index), &query, window, cx);
|
||||
self.select_next_match(&SelectNextMatch, window, cx);
|
||||
}
|
||||
should_propagate = false;
|
||||
}
|
||||
}
|
||||
if !self.dismissed
|
||||
&& self.active_search.is_some()
|
||||
&& let Some(searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(query) = self.active_search.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
if let Some(active_index) = self.active_match_index {
|
||||
let query = query
|
||||
.as_ref()
|
||||
.clone()
|
||||
.with_replacement(self.replacement(cx));
|
||||
searchable_item.replace(matches.at(active_index), &query, window, cx);
|
||||
self.select_next_match(&SelectNextMatch, window, cx);
|
||||
}
|
||||
should_propagate = false;
|
||||
}
|
||||
if !should_propagate {
|
||||
cx.stop_propagation();
|
||||
|
@ -1410,21 +1400,19 @@ impl BufferSearchBar {
|
|||
}
|
||||
|
||||
pub fn replace_all(&mut self, _: &ReplaceAll, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if !self.dismissed && self.active_search.is_some() {
|
||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||
if let Some(query) = self.active_search.as_ref() {
|
||||
if let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
let query = query
|
||||
.as_ref()
|
||||
.clone()
|
||||
.with_replacement(self.replacement(cx));
|
||||
searchable_item.replace_all(&mut matches.iter(), &query, window, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !self.dismissed
|
||||
&& self.active_search.is_some()
|
||||
&& let Some(searchable_item) = self.active_searchable_item.as_ref()
|
||||
&& let Some(query) = self.active_search.as_ref()
|
||||
&& let Some(matches) = self
|
||||
.searchable_items_with_matches
|
||||
.get(&searchable_item.downgrade())
|
||||
{
|
||||
let query = query
|
||||
.as_ref()
|
||||
.clone()
|
||||
.with_replacement(self.replacement(cx));
|
||||
searchable_item.replace_all(&mut matches.iter(), &query, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -775,15 +775,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);
|
||||
}
|
||||
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()))
|
||||
|
@ -947,14 +947,14 @@ impl ProjectSearchView {
|
|||
{
|
||||
let new_query = search_view.update(cx, |search_view, cx| {
|
||||
let new_query = search_view.build_search_query(cx);
|
||||
if new_query.is_some() {
|
||||
if let Some(old_query) = search_view.entity.read(cx).active_query.clone() {
|
||||
search_view.query_editor.update(cx, |editor, cx| {
|
||||
editor.set_text(old_query.as_str(), window, cx);
|
||||
});
|
||||
search_view.search_options = SearchOptions::from_query(&old_query);
|
||||
search_view.adjust_query_regex_language(cx);
|
||||
}
|
||||
if new_query.is_some()
|
||||
&& let Some(old_query) = search_view.entity.read(cx).active_query.clone()
|
||||
{
|
||||
search_view.query_editor.update(cx, |editor, cx| {
|
||||
editor.set_text(old_query.as_str(), window, cx);
|
||||
});
|
||||
search_view.search_options = SearchOptions::from_query(&old_query);
|
||||
search_view.adjust_query_regex_language(cx);
|
||||
}
|
||||
new_query
|
||||
});
|
||||
|
@ -1844,8 +1844,8 @@ impl ProjectSearchBar {
|
|||
),
|
||||
] {
|
||||
if editor.focus_handle(cx).is_focused(window) {
|
||||
if editor.read(cx).text(cx).is_empty() {
|
||||
if let Some(new_query) = search_view
|
||||
if editor.read(cx).text(cx).is_empty()
|
||||
&& let Some(new_query) = search_view
|
||||
.entity
|
||||
.read(cx)
|
||||
.project
|
||||
|
@ -1853,10 +1853,9 @@ impl ProjectSearchBar {
|
|||
.search_history(kind)
|
||||
.current(search_view.entity.read(cx).cursor(kind))
|
||||
.map(str::to_string)
|
||||
{
|
||||
search_view.set_search_editor(kind, &new_query, window, cx);
|
||||
return;
|
||||
}
|
||||
{
|
||||
search_view.set_search_editor(kind, &new_query, window, cx);
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(new_query) = search_view.entity.update(cx, |model, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue