mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
refactor key handling in diff
This commit is contained in:
parent
e8204d5a6d
commit
d332e7e586
2 changed files with 14 additions and 17 deletions
|
|
@ -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::{
|
||||
|
|
@ -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 => {
|
||||
|
||||
keys::HOME | keys::SHIFT_UP => {
|
||||
self.scroll(ScrollType::Home);
|
||||
true
|
||||
}
|
||||
KeyCode::Home => {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue