fix(tui): allow navigating filtered results after searching
enter now confirms the search and returns focus to the list so items can be selected, toggled, etc. pressing / returns to the search bar with the query intact, esc clears it.
This commit is contained in:
1 parent
7c1de45a2a
commit
aa19e5bde1
6 files changed
+32
No files matched your search
@@ -15,6 +15,9 @@ impl App {
|
|||||||
if self.focused == FocusedArea::OverviewExpanded {
|
if self.focused == FocusedArea::OverviewExpanded {
|
||||||
if self.log_overlay_search.active {
|
if self.log_overlay_search.active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
self.log_overlay_search.confirm();
|
||||||
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.log_overlay_search.deactivate();
|
self.log_overlay_search.deactivate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,6 +233,11 @@ impl ContentListState {
|
|||||||
fn handle_search_keys(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
fn handle_search_keys(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
||||||
if state.search.active {
|
if state.search.active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
state.search.confirm();
|
||||||
|
state.list_state.selected = Some(0);
|
||||||
|
state.update_scrollbar();
|
||||||
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
state.search.deactivate();
|
state.search.deactivate();
|
||||||
state.list_state.selected = Some(0);
|
state.list_state.selected = Some(0);
|
||||||
|
|||||||
@@ -168,6 +168,11 @@ impl WidgetKey for State {
|
|||||||
fn handle_key(&mut self, key_event: &crossterm::event::KeyEvent) {
|
fn handle_key(&mut self, key_event: &crossterm::event::KeyEvent) {
|
||||||
if self.search.active {
|
if self.search.active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
self.search.confirm();
|
||||||
|
self.list_state.selected = Some(0);
|
||||||
|
self.update_scrollbar();
|
||||||
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.search.deactivate();
|
self.search.deactivate();
|
||||||
self.list_state.selected = Some(0);
|
self.list_state.selected = Some(0);
|
||||||
|
|||||||
@@ -225,6 +225,10 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
|
|||||||
if state.viewer_focused {
|
if state.viewer_focused {
|
||||||
if state.viewer_search.active {
|
if state.viewer_search.active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
state.viewer_search.confirm();
|
||||||
|
state.viewer_scroll = 0;
|
||||||
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
state.viewer_search.deactivate();
|
state.viewer_search.deactivate();
|
||||||
state.viewer_scroll = 0;
|
state.viewer_scroll = 0;
|
||||||
@@ -288,6 +292,11 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
|
|||||||
} else {
|
} else {
|
||||||
if state.search.active {
|
if state.search.active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
state.search.confirm();
|
||||||
|
state.list_state.selected = Some(0);
|
||||||
|
state.update_scrollbar();
|
||||||
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
state.search.deactivate();
|
state.search.deactivate();
|
||||||
state.list_state.selected = Some(0);
|
state.list_state.selected = Some(0);
|
||||||
|
|||||||
@@ -182,6 +182,10 @@ impl ScreenshotsState {
|
|||||||
pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
|
pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
|
||||||
if state.search.active {
|
if state.search.active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
|
KeyCode::Enter => {
|
||||||
|
state.search.confirm();
|
||||||
|
state.selected = 0;
|
||||||
|
}
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
state.search.deactivate();
|
state.search.deactivate();
|
||||||
state.selected = 0;
|
state.selected = 0;
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ impl SearchState {
|
|||||||
self.query.clear();
|
self.query.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exit search mode but keep the filter active so the user can
|
||||||
|
// navigate the filtered results
|
||||||
|
pub fn confirm(&mut self) {
|
||||||
|
self.active = false;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, c: char) {
|
pub fn push(&mut self, c: char) {
|
||||||
self.query.push(c);
|
self.query.push(c);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user