Focus active item when pressing tab in buffer search bar (#3859)

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-01-03 16:58:30 +01:00 committed by GitHub
commit b348d0e59f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ use crate::{
ToggleCaseSensitive, ToggleReplace, ToggleWholeWord,
};
use collections::HashMap;
use editor::{Editor, EditorElement, EditorStyle};
use editor::{Editor, EditorElement, EditorStyle, Tab};
use futures::channel::oneshot;
use gpui::{
actions, div, impl_actions, Action, AppContext, ClickEvent, EventEmitter, FocusableView,
@ -190,6 +190,7 @@ impl Render for BufferSearchBar {
.w_full()
.gap_2()
.key_context(key_context)
.capture_action(cx.listener(Self::tab))
.on_action(cx.listener(Self::previous_history_query))
.on_action(cx.listener(Self::next_history_query))
.on_action(cx.listener(Self::dismiss))
@ -932,6 +933,14 @@ impl BufferSearchBar {
}
}
fn tab(&mut self, _: &Tab, cx: &mut ViewContext<Self>) {
if let Some(item) = self.active_searchable_item.as_ref() {
let focus_handle = item.focus_handle(cx);
cx.focus(&focus_handle);
cx.stop_propagation();
}
}
fn next_history_query(&mut self, _: &NextHistoryQuery, cx: &mut ViewContext<Self>) {
if let Some(new_query) = self.search_history.next().map(str::to_string) {
let _ = self.search(&new_query, Some(self.search_options), cx);