summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-03-02 20:23:23 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-03-02 20:23:23 -0500
commitf7f575f0b8ae14703f14c096d0b3798a6bb77684 (patch)
treeda8a352c92839a057276706bb9513ff633392acf
parent511058d3c321f4348f8ccf3d26fb24702610db21 (diff)
fix search_prev silently overwriting paste commands
- joshuto should now exit if a conflict occurs between keybindings
-rw-r--r--config/keymap.toml2
-rw-r--r--src/commands/mod.rs3
-rw-r--r--src/config/keymap.rs15
3 files changed, 15 insertions, 5 deletions
diff --git a/config/keymap.toml b/config/keymap.toml
index 72567e3..a3c3724 100644
--- a/config/keymap.toml
+++ b/config/keymap.toml
@@ -168,7 +168,7 @@ keys = [ "n" ]
command = "search_next"
[[mapcommand]]
-keys = [ "p" ]
+keys = [ "N" ]
command = "search_prev"
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index b58fd0f..1185d93 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -142,8 +142,7 @@ pub fn from_args(command: &str, args: Option<&Vec<String>>) -> Option<Box<Joshut
}
}
}
- let paste = self::PasteFiles::new(options);
- Some(Box::new(paste))
+ Some(Box::new(self::PasteFiles::new(options)))
}
"quit" => Some(Box::new(self::Quit::new())),
"reload_dir_list" => Some(Box::new(self::ReloadDirList::new())),
diff --git a/src/config/keymap.rs b/src/config/keymap.rs
index 6b4a1f1..979f68d 100644
--- a/src/config/keymap.rs
+++ b/src/config/keymap.rs
@@ -1,5 +1,6 @@
use serde_derive::Deserialize;
use std::collections::HashMap;
+use std::collections::hash_map;
use std::process::exit;
use crate::commands;
@@ -68,7 +69,17 @@ fn insert_keycommand(
) {
if keys.len() == 1 {
if let Some(s) = key_to_i32(&keys[0]) {
- map.insert(s, commands::CommandKeybind::SimpleKeybind(keycommand));
+ match map.entry(s) {
+ hash_map::Entry::Occupied(entry) => {
+ eprintln!("Error: Keybindings ambiguous");
+ exit(1);
+ }
+ hash_map::Entry::Vacant(entry) => {
+ entry.insert(commands::CommandKeybind::SimpleKeybind(keycommand));
+ }
+ }
+ } else {
+ eprintln!("Error: Failed to parse keycode: {}", keys[0]);
}
} else if let Some(s) = key_to_i32(&keys[0]) {
let mut new_map: HashMap<i32, commands::CommandKeybind>;
@@ -86,7 +97,7 @@ fn insert_keycommand(
}
insert_keycommand(&mut new_map, keycommand, &keys[1..]);
let composite_command = commands::CommandKeybind::CompositeKeybind(new_map);
- map.insert(s as i32, composite_command);
+ map.insert(s, composite_command);
}
}