Skip to content

Commit

Permalink
Modify the description of find to match changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mtimaN committed Jan 20, 2024
1 parent 395dc90 commit be9f447
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,26 +663,27 @@ impl Editor {
}

/// Try to find a query, this is called after pressing Ctrl-F and for each key that is pressed.
/// `last_match` is the last row that was matched, `forward` indicates whether to search forward
/// or backward. Returns the row of a new match, or `None` if the search was unsuccessful.
/// `q` represents the query, `lst` is the last position that was matched, `fw` indicates
/// whether to search forward or backward. Returns the position of a new match, or `None`
/// if the search was unsuccessful.
#[allow(clippy::trivially_copy_pass_by_ref)] // This Clippy recommendation is only relevant on 32 bit platforms.
fn find(&mut self, query: &str, last_match: &Option<(usize, usize)>, fwd: bool) -> Option<(usize, usize)> {
fn find(&mut self, q: &str, lst: &Option<(usize, usize)>, fw: bool) -> Option<(usize, usize)> {

Check warning on line 670 in src/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/editor.rs#L670

Added line #L670 was not covered by tests
let num_rows = self.rows.len();
let mut cur = last_match.unwrap_or_else(|| (usize::MAX, num_rows.saturating_sub(1)));
let mut cur = lst.unwrap_or_else(|| (usize::MAX, num_rows.saturating_sub(1)));
while {
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, query.as_bytes()) {
if let Some(cx) = slice_find(slice, q.as_bytes()) {
cur.0 = if cur.0 == usize::MAX { cx } else { cur.0 + cx + 1 };
(self.cursor.x, self.cursor.y, self.cursor.coff) = (cur.0, cur.1, 0);
let rx = row.cx2rx[cur.0];
row.match_segment = Some(rx..rx + query.len());
row.match_segment = Some(rx..rx + q.len());
return Some(cur);

Check warning on line 681 in src/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/editor.rs#L672-L681

Added lines #L672 - L681 were not covered by tests
} else {

Check failure on line 682 in src/editor.rs

View workflow job for this annotation

GitHub Actions / static_checks (ubuntu-latest, x86_64-unknown-linux-gnu)

[clippy-x86_64-unknown-linux-gnu] reported by reviewdog 🐶 <pre><code>error: redundant else block --> src/editor.rs:682:20 | 682 | } else { | ____________________^ 683 | | cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); 684 | | } | |_____________^ | = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else = note: `-D clippy::redundant-else` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_else)]` </code></pre> Raw Output: src/editor.rs:682:20:e: <pre><code>error: redundant else block --> src/editor.rs:682:20 | 682 | } else { | ____________________^ 683 | | cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); 684 | | } | |_____________^ | = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else = note: `-D clippy::redundant-else` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_else)]` </code></pre> __END__

Check failure on line 682 in src/editor.rs

View workflow job for this annotation

GitHub Actions / static_checks (macos-latest, x86_64-apple-darwin)

[clippy-x86_64-apple-darwin] reported by reviewdog 🐶 <pre><code>error: redundant else block --> src/editor.rs:682:20 | 682 | } else { | ____________________^ 683 | | cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); 684 | | } | |_____________^ | = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else = note: `-D clippy::redundant-else` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_else)]` </code></pre> Raw Output: src/editor.rs:682:20:e: <pre><code>error: redundant else block --> src/editor.rs:682:20 | 682 | } else { | ____________________^ 683 | | cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); 684 | | } | |_____________^ | = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else = note: `-D clippy::redundant-else` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_else)]` </code></pre> __END__

Check failure on line 682 in src/editor.rs

View workflow job for this annotation

GitHub Actions / static_checks (ubuntu-latest, wasm32-wasi)

[clippy-wasm32-wasi] reported by reviewdog 🐶 <pre><code>error: redundant else block --> src/editor.rs:682:20 | 682 | } else { | ____________________^ 683 | | cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); 684 | | } | |_____________^ | = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else = note: `-D clippy::redundant-else` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_else)]` </code></pre> Raw Output: src/editor.rs:682:20:e: <pre><code>error: redundant else block --> src/editor.rs:682:20 | 682 | } else { | ____________________^ 683 | | cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows); 684 | | } | |_____________^ | = help: remove the `else` block and move the contents out = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else = note: `-D clippy::redundant-else` implied by `-D clippy::pedantic` = help: to override `-D clippy::pedantic` add `#[allow(clippy::redundant_else)]` </code></pre> __END__
cur = (usize::MAX, (cur.1 + if fwd { 1 } else { num_rows - 1 }) % num_rows);
cur = (usize::MAX, (cur.1 + if fw { 1 } else { num_rows - 1 }) % num_rows);

Check warning on line 683 in src/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/editor.rs#L683

Added line #L683 was not covered by tests
}
// if it wrapped back to the starting point
cur == last_match.unwrap_or_else(|| (usize::MAX, num_rows.saturating_sub(1)))
cur == lst.unwrap_or_else(|| (usize::MAX, num_rows.saturating_sub(1)))

Check warning on line 686 in src/editor.rs

View check run for this annotation

Codecov / codecov/patch

src/editor.rs#L686

Added line #L686 was not covered by tests
} {}
None
}
Expand Down

0 comments on commit be9f447

Please sign in to comment.