Skip to content

Commit

Permalink
Support Object Key searches.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Nov 17, 2021
1 parent c8d878f commit 8505634
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/jless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,19 @@ impl JLess {

fn initialize_freeform_search(&mut self, direction: SearchDirection, search_term: String) {
self.search_state =
SearchState::initialize_search(&search_term, &self.viewer.flatjson.1, direction);
SearchState::initialize_search(search_term, &self.viewer.flatjson.1, direction);
}

fn initialize_object_key_search(&mut self, direction: SearchDirection) {}
fn initialize_object_key_search(&mut self, direction: SearchDirection) {
if let Some(key_range) = &self.viewer.flatjson[self.viewer.focused_row].key_range {
// Note key_range already includes quotes around key.
let needle = format!("{}: ", &self.viewer.flatjson.1[key_range.clone()]);
self.search_state =
SearchState::initialize_search(dbg!(needle), &self.viewer.flatjson.1, direction);
} else {
panic!("Handle object key search initialized not on object key");
}
}

fn jump_to_next_search_match(&mut self, jumps: usize) -> Action {
let destination = self.search_state.jump_to_match(
Expand Down
6 changes: 3 additions & 3 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ impl SearchState {
}

pub fn initialize_search(
needle: &str,
needle: String,
haystack: &str,
direction: SearchDirection,
) -> SearchState {
let regex = Regex::new(needle).unwrap();
let regex = Regex::new(&needle).unwrap();
let matches: Vec<Range<usize>> = regex.find_iter(haystack).map(|m| m.range()).collect();

SearchState {
direction,
search_term: needle.to_owned(),
search_term: needle,
compiled_regex: regex,
matches,
immediate_state: ImmediateSearchState::NotSearching,
Expand Down

0 comments on commit 8505634

Please sign in to comment.