Skip to content

Commit

Permalink
Fix search mode reset behaviour
Browse files Browse the repository at this point in the history
Resetting this mode should clear its input and results. That said, we don't
want to reset automatically when entering this mode, because that breaks jumping
to the next result from normal mode.
  • Loading branch information
jmacdonald committed Sep 10, 2024
1 parent 9201aca commit 0d82d9a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/commands/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ pub fn switch_to_select_line_mode(app: &mut Application) -> Result {
pub fn switch_to_search_mode(app: &mut Application) -> Result {
if app.workspace.current_buffer.is_some() {
app.switch_to(ModeKey::Search);
if let Mode::Search(ref mut mode) = app.mode {
mode.reset();
}
} else {
bail!(BUFFER_MISSING);
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ pub fn accept_query(app: &mut Application) -> Result {
Ok(())
}

pub fn clear_query(app: &mut Application) -> Result {
pub fn reset(app: &mut Application) -> Result {
if let Mode::Search(ref mut mode) = app.mode {
mode.input = None;
mode.reset();
} else {
bail!("Can't clear search outside of search mode");
bail!("Can't reset search outside of search mode");
};

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/input/key_map/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ normal:
"#": application::switch_to_syntax_mode
/:
- application::switch_to_search_mode
- search::clear_query
- search::reset
",": view::scroll_up
">": buffer::indent_line
"<": buffer::outdent_line
Expand Down Expand Up @@ -125,7 +125,7 @@ search:
- search::run
/:
- application::switch_to_search_mode
- search::clear_query
- search::reset
m: view::scroll_down
",": view::scroll_up
n: search::move_to_next_result
Expand Down
2 changes: 2 additions & 0 deletions src/models/application/modes/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ impl SearchMode {

pub fn reset(&mut self) {
self.insert = true;
self.input = None;
self.results = None;
}

pub fn insert_mode(&self) -> bool {
Expand Down

0 comments on commit 0d82d9a

Please sign in to comment.