more hotkeys and workdir/stage hotkey change (closes #92)

This commit is contained in:
Stephan Dilly 2020-06-02 14:07:28 +02:00
parent b3ccdb58d4
commit aa79b92f59
4 changed files with 59 additions and 23 deletions

View File

@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- changed hotkeys for selecting stage/workdir (**[w] / [s]** now to change between workdir and stage) and added hotkeys (`[1234]`) to switch to tabs directly ([#92](https://github.com/extrawurst/gitui/issues/92))
## [0.5.0] - 2020-06-01
### Changed

View File

@ -15,7 +15,7 @@ use crate::{
use anyhow::{anyhow, Result};
use asyncgit::{sync, AsyncNotification, CWD};
use crossbeam_channel::Sender;
use crossterm::event::Event;
use crossterm::event::{Event, KeyEvent};
use strings::commands;
use tui::{
backend::Backend,
@ -115,7 +115,7 @@ impl App {
pub fn event(&mut self, ev: Event) -> Result<()> {
log::trace!("event: {:?}", ev);
if self.check_quit(ev) {
if self.check_quit_key(ev) {
return Ok(());
}
@ -133,6 +133,14 @@ impl App {
self.toggle_tabs(true)?;
NeedsUpdate::COMMANDS
}
keys::TAB_1
| keys::TAB_2
| keys::TAB_3
| keys::TAB_4 => {
self.switch_tab(k)?;
NeedsUpdate::COMMANDS
}
keys::CMD_BAR_TOGGLE => {
self.cmdbar.toggle_more();
NeedsUpdate::empty()
@ -222,7 +230,7 @@ impl App {
]
);
fn check_quit(&mut self, ev: Event) -> bool {
fn check_quit_key(&mut self, ev: Event) -> bool {
if let Event::Key(e) = ev {
if let keys::EXIT = e {
self.do_quit = true;
@ -252,6 +260,18 @@ impl App {
self.set_tab(new_tab)
}
fn switch_tab(&mut self, k: KeyEvent) -> Result<()> {
match k {
keys::TAB_1 => self.set_tab(0)?,
keys::TAB_2 => self.set_tab(1)?,
keys::TAB_3 => self.set_tab(2)?,
keys::TAB_4 => self.set_tab(3)?,
_ => (),
}
Ok(())
}
fn set_tab(&mut self, tab: usize) -> Result<()> {
let tabs = self.get_tabs();
for (i, t) in tabs.into_iter().enumerate() {
@ -353,14 +373,16 @@ impl App {
}
}
res.push(
CommandInfo::new(
commands::TOGGLE_TABS,
true,
!self.any_popup_visible(),
)
.hidden(),
);
res.push(CommandInfo::new(
commands::TOGGLE_TABS,
true,
!self.any_popup_visible(),
));
res.push(CommandInfo::new(
commands::TOGGLE_TABS_DIRECT,
true,
!self.any_popup_visible(),
));
res.push(
CommandInfo::new(
@ -405,7 +427,7 @@ impl App {
strings::TAB_STATUS,
strings::TAB_LOG,
strings::TAB_STASHING,
"Stashes",
strings::TAB_STASHES,
])
.style(Style::default())
.highlight_style(

View File

@ -14,10 +14,14 @@ const fn with_mod(
KeyEvent { code, modifiers }
}
pub const TAB_1: KeyEvent = no_mod(KeyCode::Char('1'));
pub const TAB_2: KeyEvent = no_mod(KeyCode::Char('2'));
pub const TAB_3: KeyEvent = no_mod(KeyCode::Char('3'));
pub const TAB_4: KeyEvent = no_mod(KeyCode::Char('4'));
pub const TAB_TOGGLE: KeyEvent = no_mod(KeyCode::Tab);
pub const TAB_TOGGLE_REVERSE: KeyEvent = no_mod(KeyCode::BackTab);
pub const FOCUS_WORKDIR: KeyEvent = no_mod(KeyCode::Char('1'));
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
pub const FOCUS_WORKDIR: KeyEvent = no_mod(KeyCode::Char('w'));
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('s'));
pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);
pub const FOCUS_LEFT: KeyEvent = no_mod(KeyCode::Left);
pub const EXIT: KeyEvent =

View File

@ -1,10 +1,11 @@
pub static TITLE_STATUS: &str = "Unstaged Changes [1]";
pub static TITLE_STATUS: &str = "Unstaged Changes [w]";
pub static TITLE_DIFF: &str = "Diff: ";
pub static TITLE_INDEX: &str = "Staged Changes [2]";
pub static TITLE_INDEX: &str = "Staged Changes [s]";
pub static TAB_STATUS: &str = "Status";
pub static TAB_STASHING: &str = "Stashing";
pub static TAB_LOG: &str = "Log";
pub static TAB_STATUS: &str = "Status [1]";
pub static TAB_LOG: &str = "Log [2]";
pub static TAB_STASHING: &str = "Stashing [3]";
pub static TAB_STASHES: &str = "Stashes [4]";
pub static TAB_DIVIDER: &str = " | ";
pub static CMD_SPLITTER: &str = " ";
@ -39,8 +40,14 @@ pub mod commands {
///
pub static TOGGLE_TABS: CommandText = CommandText::new(
"Tabs [tab]",
"switch top level tabs",
"Next [tab]",
"switch to next tab",
CMD_GROUP_GENERAL,
);
///
pub static TOGGLE_TABS_DIRECT: CommandText = CommandText::new(
"Tab [1234]",
"switch top level tabs directly",
CMD_GROUP_GENERAL,
);
///
@ -94,7 +101,7 @@ pub mod commands {
.hide_help();
///
pub static SELECT_STAGING: CommandText = CommandText::new(
"Focus Stage [2]",
"Focus Stage [s]",
"focus/select staging area",
CMD_GROUP_GENERAL,
);
@ -106,7 +113,7 @@ pub mod commands {
);
///
pub static SELECT_UNSTAGED: CommandText = CommandText::new(
"Focus Unstaged [1]",
"Focus Unstaged [w]",
"focus/select unstaged area",
CMD_GROUP_GENERAL,
);