Skip to content
Snippets Groups Projects
Commit 0e1223eb authored by gwenn's avatar gwenn
Browse files

Fix repeated char search

parent 42a02d66
No related branches found
No related tags found
No related merge requests found
...@@ -419,7 +419,8 @@ impl LineBuffer { ...@@ -419,7 +419,8 @@ impl LineBuffer {
.char_indices() .char_indices()
.rev() .rev()
.filter(|&(_, ch)| ch == c) .filter(|&(_, ch)| ch == c)
.nth(n - 1) .take(n)
.last()
.map(|(i, _)| i) .map(|(i, _)| i)
} }
CharSearch::Forward(c) | CharSearch::Forward(c) |
...@@ -430,7 +431,8 @@ impl LineBuffer { ...@@ -430,7 +431,8 @@ impl LineBuffer {
self.buf[shift..] self.buf[shift..]
.char_indices() .char_indices()
.filter(|&(_, ch)| ch == c) .filter(|&(_, ch)| ch == c)
.nth(n - 1) .take(n)
.last()
.map(|(i, _)| i) .map(|(i, _)| i)
} else { } else {
None None
...@@ -500,8 +502,12 @@ impl LineBuffer { ...@@ -500,8 +502,12 @@ impl LineBuffer {
if self.pos == self.buf.len() { if self.pos == self.buf.len() {
return None; return None;
} }
self.buf[self.pos..].grapheme_indices(true).filter(|&(_, ch)| ch.is_alphanumeric()) self.buf[self.pos..]
.map(|(i, _)| i).next().map(|i| i + self.pos) .grapheme_indices(true)
.filter(|&(_, ch)| ch.is_alphanumeric())
.map(|(i, _)| i)
.next()
.map(|i| i + self.pos)
} }
/// Alter the next word. /// Alter the next word.
pub fn edit_word(&mut self, a: WordAction) -> bool { pub fn edit_word(&mut self, a: WordAction) -> bool {
...@@ -916,6 +922,11 @@ mod test { ...@@ -916,6 +922,11 @@ mod test {
let ok = s.move_to(CharSearch::Forward('ε'), 1); let ok = s.move_to(CharSearch::Forward('ε'), 1);
assert_eq!(true, ok); assert_eq!(true, ok);
assert_eq!(8, s.pos); assert_eq!(8, s.pos);
let mut s = LineBuffer::init("αßγδε", 2);
let ok = s.move_to(CharSearch::Forward('ε'), 10);
assert_eq!(true, ok);
assert_eq!(8, s.pos);
} }
#[test] #[test]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment