summaryrefslogtreecommitdiffstats
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
parent341ba9c5aeb1c5d9540fac5652bfc8e7c1c6601d (diff)
make it possible to rebind left and right arrow keys
Fix #438
-rw-r--r--CHANGELOG.md3
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml6
-rw-r--r--resources/default-conf.hjson4
-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
-rw-r--r--website/docs/modal.md6
10 files changed, 32 insertions, 40 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9337076..2f80601 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+### next
+- make it possible to rebind left and right arrow keys without breaking usage in input - Fix #438
+
<a name="v1.6.5"></a>
### v1.6.5 - 2021-10-01
- improve decision on whether to trim root - Fix #434
diff --git a/Cargo.lock b/Cargo.lock
index fe0434e..3c411c7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -140,7 +140,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "broot"
-version = "1.6.5"
+version = "1.6.6-dev"
dependencies = [
"ahash 0.7.4",
"ansi_colours",
@@ -180,7 +180,7 @@ dependencies = [
"strict",
"syntect",
"tempfile",
- "termimad 0.16.3",
+ "termimad 0.16.4",
"terminal-clipboard",
"toml",
"umask",
@@ -1611,9 +1611,9 @@ dependencies = [
[[package]]
name = "termimad"
-version = "0.16.3"
+version = "0.16.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d06b905c5f505c6fe06d2c1df359d4919c44aed53cb12ff9babf8d5085885a36"
+checksum = "d88221817ef21964ccccf7d8ccc35fed3bae3066a177d1fcda72d694a016a47d"
dependencies = [
"crossbeam",
"crossterm 0.21.0",
diff --git a/Cargo.toml b/Cargo.toml
index 84e5eb6..0fced8e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "broot"
-version = "1.6.5"
+version = "1.6.6-dev"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/broot"
documentation = "https://dystroy.org/broot"
@@ -53,7 +53,7 @@ splitty = "0.1"
strict = "0.1.4"
syntect = "4.5"
tempfile = "3.2"
-termimad = "0.16.3"
+termimad = "0.16.4"
terminal-clipboard = { version = "0.2.1", optional = true }
toml = "0.5"
umask = "1.0"
@@ -104,6 +104,6 @@ harness = false
# minimad = { path = "../minimad" }
# secular = { path = "../secular", features=["normalization"] }
# strict = { path = "../strict" }
-# termimad = { path = "../termimad" }
+# termimad = { path = "../termimad" }
# terminal-clipboard = { path = "../terminal-clipboard" }
# umask = { path = "../umask" }
diff --git a/resources/default-conf.hjson b/resources/default-conf.hjson
index b9e70a7..a9c8e48 100644
--- a/resources/default-conf.hjson
+++ b/resources/default-conf.hjson
@@ -37,8 +37,8 @@
###############################################################
# uncomment to activate modal mode
#
- # (you really should read https://dystroy.org/broot/vim_mode/
- # before as it may not suit anybody even among vim users)
+ # (you really should read https://dystroy.org/broot/modal/
+ # before as it may not suit everybody even among vim users)
#
# modal: true
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}",
diff --git a/website/docs/modal.md b/website/docs/modal.md
index 7c835d4..29340dd 100644
--- a/website/docs/modal.md
+++ b/website/docs/modal.md
@@ -8,7 +8,8 @@ The "modal mode", which may be familiar to vim users, changes a little the way y
- The downside is you have one letter more to type to start searching, which isn't to dismiss as searching is usually the first thing you do in broot.
I recommand you **don't** activate this mode until you really tried broot. Broot isn't a text editor and can't be confused with one. This mode may be more comfortable when you constantly jump from vim to broot but only after you understood how broot works.
-You may be an avid vim user, as I am, and still prefer not to use modality in broot. Starting in *command* mode means you have one more letter to type before searching, because search is done in *input* mode. And broot is search oriented and often used in very short sessions (less than 5 seconds from intent to launch to being back in the shell in the right directory or editing the right file in your favorite editor)
+
+You may be an avid vim user, as I am, and still prefer not to use modality in broot. Starting in *command* mode means you have one more letter to type before searching, because search is done in *input* mode. And broot is search oriented and often used in very short sessions (less than 5 seconds from intent to launch to being back in the shell in the right directory or editing the right file in your favorite editor).
# Configuration
@@ -18,11 +19,10 @@ You need first to enable the "modal mode" with this line in the configuration:
modal: true
```
```TOML
+# note that this must be near the start of the configuration file
modal = true
```
-(note: it must be at the begining of the configuration if it's in TOML)
-
If `modal` isn't set to `true`, the single letter shortcuts you define in configuration will be ignored (so you don't have to remove them if you don't want modality anymore).
# Usage