Skip to content

Commit

Permalink
Circular next match
Browse files Browse the repository at this point in the history
  • Loading branch information
Sberm committed Apr 3, 2024
1 parent 706a8fd commit cbb0d11
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ impl Browser {
}

fn next_match(&mut self) {
let mut flag;
let mut flag = false;

if self.cursor >= self.current_dir.len() {
return
}

for i in self.cursor + 1..self.current_dir.len() {
let cd = &self.current_dir[i];
flag = true;
if self.search_txt.len() > cd.chars().collect::<String>().len() {
continue;
}
flag = true;
for (j, c) in self.search_txt.iter().enumerate() {
if j < cd.len() {
if *c != cd.chars().nth(j).expect("current_dir string out of bound") {
Expand All @@ -115,6 +115,35 @@ impl Browser {
break;
}
}

/* start from 0 */
if flag == false {
for i in 0..self.cursor {
let cd = &self.current_dir[i];
flag = true;
if self.search_txt.len() > cd.chars().collect::<String>().len() {
continue;
}
for (j, c) in self.search_txt.iter().enumerate() {
if j < cd.len() {
if *c != cd.chars().nth(j).expect("current_dir string out of bound") {
flag = false;
break;
}
}
}
if flag == true {
self.cursor = i;
let (h, _) = canvas::term_size();
self.window_start = if self.cursor as isize - h as isize / 2 > 0 {
self.cursor - h / 2
} else {
0
};
break;
}
}
}
}

fn search(&mut self) {
Expand Down

0 comments on commit cbb0d11

Please sign in to comment.