Skip to content

Commit aa79b92

Browse files
author
Stephan Dilly
committed
more hotkeys and workdir/stage hotkey change (closes #92)
1 parent b3ccdb5 commit aa79b92

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- 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))
11+
912
## [0.5.0] - 2020-06-01
1013

1114
### Changed

src/app.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
use anyhow::{anyhow, Result};
1616
use asyncgit::{sync, AsyncNotification, CWD};
1717
use crossbeam_channel::Sender;
18-
use crossterm::event::Event;
18+
use crossterm::event::{Event, KeyEvent};
1919
use strings::commands;
2020
use tui::{
2121
backend::Backend,
@@ -115,7 +115,7 @@ impl App {
115115
pub fn event(&mut self, ev: Event) -> Result<()> {
116116
log::trace!("event: {:?}", ev);
117117

118-
if self.check_quit(ev) {
118+
if self.check_quit_key(ev) {
119119
return Ok(());
120120
}
121121

@@ -133,6 +133,14 @@ impl App {
133133
self.toggle_tabs(true)?;
134134
NeedsUpdate::COMMANDS
135135
}
136+
keys::TAB_1
137+
| keys::TAB_2
138+
| keys::TAB_3
139+
| keys::TAB_4 => {
140+
self.switch_tab(k)?;
141+
NeedsUpdate::COMMANDS
142+
}
143+
136144
keys::CMD_BAR_TOGGLE => {
137145
self.cmdbar.toggle_more();
138146
NeedsUpdate::empty()
@@ -222,7 +230,7 @@ impl App {
222230
]
223231
);
224232

225-
fn check_quit(&mut self, ev: Event) -> bool {
233+
fn check_quit_key(&mut self, ev: Event) -> bool {
226234
if let Event::Key(e) = ev {
227235
if let keys::EXIT = e {
228236
self.do_quit = true;
@@ -252,6 +260,18 @@ impl App {
252260
self.set_tab(new_tab)
253261
}
254262

263+
fn switch_tab(&mut self, k: KeyEvent) -> Result<()> {
264+
match k {
265+
keys::TAB_1 => self.set_tab(0)?,
266+
keys::TAB_2 => self.set_tab(1)?,
267+
keys::TAB_3 => self.set_tab(2)?,
268+
keys::TAB_4 => self.set_tab(3)?,
269+
_ => (),
270+
}
271+
272+
Ok(())
273+
}
274+
255275
fn set_tab(&mut self, tab: usize) -> Result<()> {
256276
let tabs = self.get_tabs();
257277
for (i, t) in tabs.into_iter().enumerate() {
@@ -353,14 +373,16 @@ impl App {
353373
}
354374
}
355375

356-
res.push(
357-
CommandInfo::new(
358-
commands::TOGGLE_TABS,
359-
true,
360-
!self.any_popup_visible(),
361-
)
362-
.hidden(),
363-
);
376+
res.push(CommandInfo::new(
377+
commands::TOGGLE_TABS,
378+
true,
379+
!self.any_popup_visible(),
380+
));
381+
res.push(CommandInfo::new(
382+
commands::TOGGLE_TABS_DIRECT,
383+
true,
384+
!self.any_popup_visible(),
385+
));
364386

365387
res.push(
366388
CommandInfo::new(
@@ -405,7 +427,7 @@ impl App {
405427
strings::TAB_STATUS,
406428
strings::TAB_LOG,
407429
strings::TAB_STASHING,
408-
"Stashes",
430+
strings::TAB_STASHES,
409431
])
410432
.style(Style::default())
411433
.highlight_style(

src/keys.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ const fn with_mod(
1414
KeyEvent { code, modifiers }
1515
}
1616

17+
pub const TAB_1: KeyEvent = no_mod(KeyCode::Char('1'));
18+
pub const TAB_2: KeyEvent = no_mod(KeyCode::Char('2'));
19+
pub const TAB_3: KeyEvent = no_mod(KeyCode::Char('3'));
20+
pub const TAB_4: KeyEvent = no_mod(KeyCode::Char('4'));
1721
pub const TAB_TOGGLE: KeyEvent = no_mod(KeyCode::Tab);
1822
pub const TAB_TOGGLE_REVERSE: KeyEvent = no_mod(KeyCode::BackTab);
19-
pub const FOCUS_WORKDIR: KeyEvent = no_mod(KeyCode::Char('1'));
20-
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
23+
pub const FOCUS_WORKDIR: KeyEvent = no_mod(KeyCode::Char('w'));
24+
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('s'));
2125
pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);
2226
pub const FOCUS_LEFT: KeyEvent = no_mod(KeyCode::Left);
2327
pub const EXIT: KeyEvent =

src/strings.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
pub static TITLE_STATUS: &str = "Unstaged Changes [1]";
1+
pub static TITLE_STATUS: &str = "Unstaged Changes [w]";
22
pub static TITLE_DIFF: &str = "Diff: ";
3-
pub static TITLE_INDEX: &str = "Staged Changes [2]";
3+
pub static TITLE_INDEX: &str = "Staged Changes [s]";
44

5-
pub static TAB_STATUS: &str = "Status";
6-
pub static TAB_STASHING: &str = "Stashing";
7-
pub static TAB_LOG: &str = "Log";
5+
pub static TAB_STATUS: &str = "Status [1]";
6+
pub static TAB_LOG: &str = "Log [2]";
7+
pub static TAB_STASHING: &str = "Stashing [3]";
8+
pub static TAB_STASHES: &str = "Stashes [4]";
89
pub static TAB_DIVIDER: &str = " | ";
910

1011
pub static CMD_SPLITTER: &str = " ";
@@ -39,8 +40,14 @@ pub mod commands {
3940

4041
///
4142
pub static TOGGLE_TABS: CommandText = CommandText::new(
42-
"Tabs [tab]",
43-
"switch top level tabs",
43+
"Next [tab]",
44+
"switch to next tab",
45+
CMD_GROUP_GENERAL,
46+
);
47+
///
48+
pub static TOGGLE_TABS_DIRECT: CommandText = CommandText::new(
49+
"Tab [1234]",
50+
"switch top level tabs directly",
4451
CMD_GROUP_GENERAL,
4552
);
4653
///
@@ -94,7 +101,7 @@ pub mod commands {
94101
.hide_help();
95102
///
96103
pub static SELECT_STAGING: CommandText = CommandText::new(
97-
"Focus Stage [2]",
104+
"Focus Stage [s]",
98105
"focus/select staging area",
99106
CMD_GROUP_GENERAL,
100107
);
@@ -106,7 +113,7 @@ pub mod commands {
106113
);
107114
///
108115
pub static SELECT_UNSTAGED: CommandText = CommandText::new(
109-
"Focus Unstaged [1]",
116+
"Focus Unstaged [w]",
110117
"focus/select unstaged area",
111118
CMD_GROUP_GENERAL,
112119
);

0 commit comments

Comments
 (0)