Skip to content

Commit

Permalink
refactor key handling in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed May 10, 2020
1 parent e8204d5 commit d332e7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/components/diff.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::{CommandBlocking, DrawableComponent};
use crate::{
components::{CommandInfo, Component},
keys,
queue::{InternalEvent, Queue},
strings,
};
use asyncgit::{hash, DiffLine, DiffLineType, FileDiff};
use crossterm::event::{Event, KeyCode, KeyModifiers};
use crossterm::event::Event;
use std::{borrow::Cow, cmp, convert::TryFrom};
use strings::commands;
use tui::{
Expand Down Expand Up @@ -367,34 +368,26 @@ impl Component for DiffComponent {
fn event(&mut self, ev: Event) -> bool {
if self.focused {
if let Event::Key(e) = ev {
let has_shift =
e.modifiers.contains(KeyModifiers::SHIFT);
return match e.code {
KeyCode::Down if !has_shift => {
return match e {
keys::MOVE_DOWN => {
self.scroll(ScrollType::Down);
true
}
KeyCode::Down if has_shift => {
keys::SHIFT_DOWN | keys::END => {
self.scroll(ScrollType::End);
true
}
KeyCode::End => {
self.scroll(ScrollType::End);
true
}
KeyCode::Up if has_shift => {
self.scroll(ScrollType::Home);
true
}
KeyCode::Home => {

keys::HOME | keys::SHIFT_UP => {
self.scroll(ScrollType::Home);
true
}
KeyCode::Up if !has_shift => {

keys::MOVE_UP => {
self.scroll(ScrollType::Up);
true
}
KeyCode::Enter => {
keys::ENTER => {
self.add_hunk();
true
}
Expand Down
4 changes: 4 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ pub const OPEN_HELP: KeyEvent = no_mod(KeyCode::Char('h'));
pub const MOVE_LEFT: KeyEvent = no_mod(KeyCode::Left);
pub const MOVE_RIGHT: KeyEvent = no_mod(KeyCode::Right);
pub const HOME: KeyEvent = no_mod(KeyCode::Home);
pub const END: KeyEvent = no_mod(KeyCode::End);
pub const MOVE_UP: KeyEvent = no_mod(KeyCode::Up);
pub const MOVE_DOWN: KeyEvent = no_mod(KeyCode::Down);
pub const SHIFT_UP: KeyEvent =
with_mod(KeyCode::Up, KeyModifiers::SHIFT);
pub const SHIFT_DOWN: KeyEvent =
with_mod(KeyCode::Down, KeyModifiers::SHIFT);
pub const ENTER: KeyEvent = no_mod(KeyCode::Enter);
pub const STATUS_STAGE_FILE: KeyEvent = no_mod(KeyCode::Enter);
pub const STATUS_RESET_FILE: KeyEvent =
with_mod(KeyCode::Char('D'), KeyModifiers::SHIFT);

0 comments on commit d332e7e

Please sign in to comment.