diff options
author | Nathan Vegdahl | 2021-07-27 06:09:58 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-27 06:09:58 +0000 |
commit | 84f8167fd1d54a5ebf924d6d4a43bd24cfe40dd2 (patch) | |
tree | 3040b3980a28b07c9e4ecf6c4719c4b40a926f09 /helix-core/src | |
parent | 5229c5387f1769dea42b2362454c1ed49746e247 (diff) |
Use `match` for branching on the `Direction` enum in more places.
Diffstat (limited to 'helix-core/src')
-rw-r--r-- | helix-core/src/movement.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index 4af82a1d..38e14594 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -34,10 +34,9 @@ pub fn move_horizontally( let pos = range.cursor(slice); // Compute the new position. - let new_pos = if dir == Direction::Backward { - nth_prev_grapheme_boundary(slice, pos, count) - } else { - nth_next_grapheme_boundary(slice, pos, count) + let new_pos = match dir { + Direction::Forward => nth_next_grapheme_boundary(slice, pos, count), + Direction::Backward => nth_prev_grapheme_boundary(slice, pos, count), }; // Compute the final new range. @@ -59,10 +58,9 @@ pub fn move_vertically( // Compute the new position. let (new_pos, new_row) = { - let new_row = if dir == Direction::Backward { - row.saturating_sub(count) - } else { - (row + count).min(slice.len_lines().saturating_sub(1)) + let new_row = match dir { + Direction::Forward => (row + count).min(slice.len_lines().saturating_sub(1)), + Direction::Backward => row.saturating_sub(count), }; let new_col = col.max(horiz as usize); ( |