Skip to content

Commit

Permalink
Broaden syntax mode reset to include input, mode, and results
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Oct 5, 2024
1 parent 8f4c924 commit d3930ed
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/models/application/modes/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ impl SyntaxMode {
}

pub fn reset(&mut self, syntaxes: Vec<String>, config: SearchSelectConfig) {
self.input.clear();
self.insert = true;
self.syntaxes = syntaxes;
self.results = SelectableVec::new(Vec::new());
self.config = config;
}
}
Expand Down Expand Up @@ -82,3 +85,28 @@ impl SearchSelectMode<String> for SyntaxMode {
&self.config
}
}

#[cfg(test)]
mod tests {
use super::SyntaxMode;
use crate::models::application::modes::{SearchSelectConfig, SearchSelectMode};

#[test]
fn reset_clears_query_mode_and_results() {
let config = SearchSelectConfig::default();
let mut mode = SyntaxMode::new(config.clone());

mode.reset(vec![String::from("syntax")], config.clone());
mode.query().push_str("syntax");
mode.set_insert_mode(false);
mode.search();

// Ensure we have results before reset
assert!(mode.results.len() > 0);

mode.reset(vec![], config);
assert_eq!(mode.query(), "");
assert_eq!(mode.insert_mode(), true);
assert_eq!(mode.results.len(), 0);
}
}

0 comments on commit d3930ed

Please sign in to comment.