Skip to content

Commit 0ec3a47

Browse files
authored
fix(keymaps): some kind of vim-alike keymaps (#510)
remapped <kbd>i</kbd> to <kbd>?</kbd> for help added <kbd>up</kbd>: <kbd>k</kbd> added <kbd>down</kbd>: <kbd>j</kbd> added search deletion keymap: <kbd>ctrl-u</kbd> remapped show qr-code from <kbd>k</kbd> to <kbd>Space</kbd> <kbd>Esc</kbd> will quit search mode, not app
2 parents 4008f63 + 9d4573f commit 0ec3a47

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

src/interface/app.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,7 @@ impl<'a> App<'a> {
288288
String::new()
289289
};
290290

291-
text.push_str(
292-
"
293-
294-
Press I to get help
295-
",
296-
);
291+
text.push_str("\n\n Press '?' to get help\n");
297292
let paragraph = Paragraph::new(text)
298293
.block(Block::default().title("Code info").borders(Borders::ALL))
299294
.style(Style::default().fg(Color::White).bg(Color::Reset))

src/interface/handlers/main_window.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ use super::{handle_exit, show_popup};
1717

1818
pub(super) fn main_handler(key_event: KeyEvent, app: &mut App) {
1919
match key_event.code {
20-
// exit application on ESC
21-
KeyCode::Esc => {
22-
handle_exit(app);
20+
// exit application on ESC or Q
21+
KeyCode::Esc | KeyCode::Char('q' | 'Q') => {
22+
if app.focus != Focus::SearchBar {
23+
handle_exit(app);
24+
}
2325
}
2426
// exit application on Ctrl-D
2527
KeyCode::Char('d' | 'D' | 'c') => {
@@ -38,21 +40,15 @@ pub(super) fn main_handler(key_event: KeyEvent, app: &mut App) {
3840
);
3941
}
4042
}
41-
// exit application on Q
42-
KeyCode::Char('q' | 'Q') => {
43-
if app.focus != Focus::SearchBar {
44-
handle_exit(app);
45-
}
46-
}
4743

4844
// Move into the table
49-
KeyCode::Up => {
45+
KeyCode::Up | KeyCode::Char('k') => {
5046
app.print_percentage = true;
5147
app.current_page = Main;
5248
app.table.previous();
5349
}
5450

55-
KeyCode::Down => {
51+
KeyCode::Down | KeyCode::Char('j') => {
5652
app.print_percentage = true;
5753
app.current_page = Main;
5854
app.table.next();
@@ -68,19 +64,19 @@ pub(super) fn main_handler(key_event: KeyEvent, app: &mut App) {
6864
handle_counter_switch(app, false);
6965
}
7066

71-
KeyCode::Char('k' | 'K') => handle_switch_page(app, Qrcode),
67+
KeyCode::Char(' ') => handle_switch_page(app, Qrcode),
7268

73-
KeyCode::Char('i' | 'I') => {
69+
KeyCode::Char('?') => {
7470
let info_text = String::from(
7571
"
7672
Press:
7773
d -> Delete selected code
7874
+ -> Increment the HOTP counter
7975
- -> Decrement the HOTP counter
80-
k -> Show QRCode of the selected element
76+
Space -> Show QRCode of the selected element
8177
Enter -> Copy the OTP Code to the clipboard
82-
CTRL-F -> Search codes
83-
CTRL-W -> Clear the search query
78+
CTRL-F | '/' -> Search codes
79+
CTRL-W | CTRL-U -> Clear the search query
8480
q, CTRL-D, Esc -> Exit the application
8581
",
8682
);

src/interface/handlers/search_bar.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pub(super) fn search_bar_handler(key_event: KeyEvent, app: &mut App) {
88
match key_event.code {
99
KeyCode::Char(c) => {
1010
if key_event.modifiers == KeyModifiers::CONTROL {
11-
match c {
12-
'f' | 'F' => {
11+
match c.to_ascii_lowercase() {
12+
'f' => {
1313
app.search_query.clear();
1414
app.focus = Focus::MainPage;
1515
}
16-
'c' | 'C' => handle_exit(app),
17-
'w' | 'W' => app.search_query.clear(),
16+
'c' => handle_exit(app),
17+
'w' | 'u' => app.search_query.clear(),
1818
_ => {}
1919
}
2020
} else {

0 commit comments

Comments
 (0)