summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-10-22 13:21:02 +0200
committerCanop <cano.petrole@gmail.com>2021-10-22 13:21:02 +0200
commit41c280e1582d8402f751d22cf82f61d4c9506c73 (patch)
treed534f1d247c4a3554e9213d578e106b649742e34 /src
parent341ba9c5aeb1c5d9540fac5652bfc8e7c1c6601d (diff)
make it possible to rebind left and right arrow keys
Fix #438
Diffstat (limited to 'src')
-rw-r--r--src/command/panel_input.rs17
-rw-r--r--src/keys.rs13
-rw-r--r--src/shell_install/bash.rs1
-rw-r--r--src/shell_install/mod.rs2
-rw-r--r--src/verb/builtin.rs12
5 files changed, 17 insertions, 28 deletions
diff --git a/src/command/panel_input.rs b/src/command/panel_input.rs
index ff98b32..b387c88 100644
--- a/src/command/panel_input.rs
+++ b/src/command/panel_input.rs
@@ -271,7 +271,7 @@ impl PanelInput {
}
// we now check if the key is the trigger key of one of the verbs
- if keys::is_key_allowed_in_mode(key, mode) {
+ if keys::is_key_allowed_for_verb(key, mode, raw.is_empty()) {
for (index, verb) in con.verb_store.verbs.iter().enumerate() {
for verb_key in &verb.keys {
if *verb_key != key {
@@ -308,21 +308,6 @@ impl PanelInput {
}
}
- if key == keys::LEFT && raw.is_empty() {
- let internal = Internal::back;
- return Command::Internal {
- internal,
- input_invocation: parts.verb_invocation,
- };
- }
-
- if key == keys::RIGHT && raw.is_empty() {
- return Command::Internal {
- internal: Internal::open_stay,
- input_invocation: None,
- };
- }
-
// input field management
if mode == Mode::Input {
if self.input_field.apply_event(&event) {
diff --git a/src/keys.rs b/src/keys.rs
index 3e1158c..4019c21 100644
--- a/src/keys.rs
+++ b/src/keys.rs
@@ -85,13 +85,18 @@ pub fn is_reserved(key: KeyEvent) -> bool {
key == BACKSPACE || key == DELETE || key == ESC
}
-pub fn is_key_allowed_in_mode(key: KeyEvent, mode: Mode) -> bool {
+pub fn is_key_allowed_for_verb(
+ key: KeyEvent,
+ mode: Mode,
+ input_is_empty: bool,
+) -> bool {
match mode {
Mode::Input => {
// in input mode, keys normally used in the input are forbidden
- match key {
- KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::NONE } => false,
- _ => true,
+ if key==LEFT || key==RIGHT {
+ input_is_empty
+ } else {
+ !matches!(key, KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::NONE })
}
}
Mode::Command => true,
diff --git a/src/shell_install/bash.rs b/src/shell_install/bash.rs
index 6516400..e98dbc3 100644
--- a/src/shell_install/bash.rs
+++ b/src/shell_install/bash.rs
@@ -20,7 +20,6 @@ use {
regex::Captures,
std::{env, fs::OpenOptions, io::Write, path::PathBuf},
termimad::{
- minimad,
mad_print_inline,
},
};
diff --git a/src/shell_install/mod.rs b/src/shell_install/mod.rs
index 73b8ac8..e6a54b8 100644
--- a/src/shell_install/mod.rs
+++ b/src/shell_install/mod.rs
@@ -5,7 +5,7 @@ use {
path::{Path, PathBuf},
str::FromStr,
},
- termimad::{minimad, mad_print_inline, MadSkin},
+ termimad::{mad_print_inline, MadSkin},
};
mod bash;
diff --git a/src/verb/builtin.rs b/src/verb/builtin.rs
index 917832d..00e161a 100644
--- a/src/verb/builtin.rs
+++ b/src/verb/builtin.rs
@@ -67,6 +67,12 @@ pub fn builtin_verbs() -> Vec<Verb> {
internal(input_go_word_left).no_doc(),
internal(input_go_word_right).no_doc(),
+ // arrow keys bindings
+ internal(back).with_key(LEFT),
+ internal(open_stay).with_key(RIGHT),
+ internal(line_down).with_key(DOWN).with_char_key('j'),
+ internal(line_up).with_key(UP).with_char_key('k'),
+
// those two operations are mapped on ALT-ENTER, one
// for directories and the other one for the other files
internal(open_leave) // calls the system open
@@ -123,12 +129,6 @@ pub fn builtin_verbs() -> Vec<Verb> {
#[cfg(feature="clipboard")]
internal(input_paste)
.with_control_key('v'),
- internal(line_down)
- .with_key(DOWN)
- .with_char_key('j'),
- internal(line_up)
- .with_key(UP)
- .with_char_key('k'),
external(
"mkdir {subpath}",
"mkdir -p {subpath:path-from-directory}",