From 03b802bbd62bc16c9d550576b50a599d1d0e6400 Mon Sep 17 00:00:00 2001 From: Matei Mantu Date: Sat, 20 Jan 2024 13:05:52 +0200 Subject: [PATCH] Fix loop condition in line. Optimize to 1022 LOC. Add TODO --- src/editor.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 18adebd..138248f 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -671,6 +671,7 @@ impl Editor { let num_rows = self.rows.len(); let mut cur = lst.unwrap_or_else(|| (usize::MAX, num_rows.saturating_sub(1))); while { + // TODO: add find backwards on the same line let row = &mut self.rows[cur.1]; let slice = if cur.0 == usize::MAX { &row.chars[..] } else { &row.chars[cur.0 + 1..] }; if let Some(cx) = slice_find(slice, q.as_bytes()) { @@ -679,11 +680,10 @@ impl Editor { let rx = row.cx2rx[cur.0]; row.match_segment = Some(rx..rx + q.len()); return Some(cur); - } else { - cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); } - // if it wrapped back to the starting point - cur == lst.unwrap_or_else(|| (usize::MAX, num_rows.saturating_sub(1))) + cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); + // if it wrapped back to the starting line + cur.1 != lst.map_or(num_rows.saturating_sub(1), |lst| lst.1) } {} None }