summaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-06-22 13:51:50 +0200
committerCanop <cano.petrole@gmail.com>2020-06-22 13:51:50 +0200
commitd21fbdebbb0c58bac98e69419c8c4deb7d37a27a (patch)
treeddebe40242abc617a00a302e905ceb29902637eb /src/command
parent0785091302b6118c19f2a6537f7a7337745af0b2 (diff)
new internal to define readline-like input edition shortcuts
You may now add this kind of shortcuts: ```toml [[verbs]] key = "alt-b" execution = ":input_go_word_left" [[verbs]] key = "alt-f" execution = ":input_go_word_right" [[verbs]] key = "alt-l" execution = ":input_del_word_left" [[verbs]] key = "alt-r" execution = ":input_del_word_right" ``` Fix #235
Diffstat (limited to 'src/command')
-rw-r--r--src/command/event.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/command/event.rs b/src/command/event.rs
index b431d89..7a5bbbe 100644
--- a/src/command/event.rs
+++ b/src/command/event.rs
@@ -9,7 +9,7 @@ use {
errors::ProgramError,
keys,
skin::PanelSkin,
- verb::Internal,
+ verb::{Internal, Verb, VerbExecution},
},
termimad::{Area, Event, InputField},
};
@@ -69,6 +69,33 @@ impl PanelInput {
Ok(cmd)
}
+ /// check whether the verb is an action on the input (like
+ /// deleting a word) and if it's the case, applies it and
+ /// return true
+ fn handle_input_related_verb(
+ &mut self,
+ verb: &Verb,
+ _con: &AppContext,
+ ) -> bool {
+ if let VerbExecution::Internal(internal_exec) = &verb.execution {
+ match internal_exec.internal {
+ Internal::input_del_char_left => self.input_field.del_char_left(),
+ Internal::input_del_char_below => self.input_field.del_char_below(),
+ Internal::input_del_word_left => self.input_field.del_word_left(),
+ Internal::input_del_word_right => self.input_field.del_word_right(),
+ Internal::input_go_left => self.input_field.move_left(),
+ Internal::input_go_right => self.input_field.move_right(),
+ Internal::input_go_word_left => self.input_field.move_word_left(),
+ Internal::input_go_word_right => self.input_field.move_word_right(),
+ Internal::input_go_to_start => self.input_field.move_to_start(),
+ Internal::input_go_to_end => self.input_field.move_to_end(),
+ _ => false,
+ }
+ } else {
+ false
+ }
+ }
+
/// consume the event to
/// - maybe change the input
/// - build a command
@@ -177,6 +204,9 @@ impl PanelInput {
for (index, verb) in con.verb_store.verbs.iter().enumerate() {
for verb_key in &verb.keys {
if *verb_key == key {
+ if self.handle_input_related_verb(verb, con) {
+ return Command::from_raw(self.input_field.get_content(), false);
+ }
if selection_type.respects(verb.selection_condition) {
return Command::VerbTrigger {
index,