|
1 | 1 | use crate::{
|
2 |
| - components::{CommandBlocking, CommandInfo, Component}, |
| 2 | + components::{ |
| 3 | + CommandBlocking, CommandInfo, Component, ScrollType, |
| 4 | + }, |
3 | 5 | keys,
|
4 | 6 | strings::commands,
|
5 | 7 | };
|
@@ -158,19 +160,24 @@ impl Revlog {
|
158 | 160 | }
|
159 | 161 | }
|
160 | 162 |
|
161 |
| - fn move_selection(&mut self, up: bool) { |
| 163 | + fn move_selection(&mut self, scroll: ScrollType) { |
162 | 164 | self.update_scroll_speed();
|
163 | 165 |
|
164 | 166 | #[allow(clippy::cast_possible_truncation)]
|
165 | 167 | let speed_int = usize::try_from(self.scroll_state.1 as i64)
|
166 | 168 | .unwrap()
|
167 | 169 | .max(1);
|
168 | 170 |
|
169 |
| - if up { |
170 |
| - self.selection = self.selection.saturating_sub(speed_int); |
171 |
| - } else { |
172 |
| - self.selection = self.selection.saturating_add(speed_int); |
173 |
| - } |
| 171 | + self.selection = match scroll { |
| 172 | + ScrollType::Up => { |
| 173 | + self.selection.saturating_sub(speed_int) |
| 174 | + } |
| 175 | + ScrollType::Down => { |
| 176 | + self.selection.saturating_add(speed_int) |
| 177 | + } |
| 178 | + ScrollType::Home => 0, |
| 179 | + _ => self.selection, |
| 180 | + }; |
174 | 181 |
|
175 | 182 | self.selection = cmp::min(self.selection, self.selection_max);
|
176 | 183 |
|
@@ -278,11 +285,15 @@ impl Component for Revlog {
|
278 | 285 | if let Event::Key(k) = ev {
|
279 | 286 | return match k {
|
280 | 287 | keys::MOVE_UP => {
|
281 |
| - self.move_selection(true); |
| 288 | + self.move_selection(ScrollType::Up); |
282 | 289 | true
|
283 | 290 | }
|
284 | 291 | keys::MOVE_DOWN => {
|
285 |
| - self.move_selection(false); |
| 292 | + self.move_selection(ScrollType::Down); |
| 293 | + true |
| 294 | + } |
| 295 | + keys::SHIFT_UP | keys::HOME => { |
| 296 | + self.move_selection(ScrollType::Home); |
286 | 297 | true
|
287 | 298 | }
|
288 | 299 | _ => false,
|
|
0 commit comments