trying to make the intro and admin with general keybindings
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
# config.toml
|
||||
[keybindings]
|
||||
|
||||
[keybindings.general]
|
||||
enter_command_mode = [":", "ctrl+;"]
|
||||
|
||||
[keybindings.general]
|
||||
move_up = ["k", "Up"]
|
||||
move_down = ["j", "Down"]
|
||||
next_option = ["l", "Right"]
|
||||
|
||||
@@ -56,6 +56,11 @@ impl Config {
|
||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
||||
}
|
||||
|
||||
/// Common actions for Edit/Read-only modes
|
||||
pub fn get_common_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
||||
self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers)
|
||||
}
|
||||
|
||||
/// Gets an action for a key in Read-Only mode, also checking common keybindings.
|
||||
pub fn get_read_only_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
||||
self.get_action_for_key_in_mode(&self.keybindings.read_only, key, modifiers)
|
||||
@@ -89,8 +94,12 @@ impl Config {
|
||||
match (show_general_mode, command_mode, is_edit_mode) {
|
||||
(true, _, _) => self.get_general_action(key, modifiers),
|
||||
(_, true, _) => self.get_command_action_for_key(key, modifiers),
|
||||
(_, _, true) => self.get_edit_action_for_key(key, modifiers),
|
||||
_ => self.get_read_only_action_for_key(key, modifiers),
|
||||
(_, _, true) => self.get_edit_action_for_key(key, modifiers)
|
||||
.or_else(|| self.get_common_action(key, modifiers)),
|
||||
_ => self.get_read_only_action_for_key(key, modifiers)
|
||||
.or_else(|| self.get_common_action(key, modifiers))
|
||||
// Add global bindings check for read-only mode
|
||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,15 @@ impl EventHandler {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some("enter_command_mode") = config.get_action_for_key_in_mode(
|
||||
&config.keybindings.global,
|
||||
key_code,
|
||||
modifiers
|
||||
) {
|
||||
self.command_mode = true;
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
|
||||
// If no general action matched, return to stay in general mode
|
||||
return Ok((false, String::new()));
|
||||
@@ -175,11 +184,14 @@ impl EventHandler {
|
||||
modifiers
|
||||
);
|
||||
|
||||
// Block command mode entry from edit mode
|
||||
if let Some("enter_command_mode") = context_action {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
self.command_message.clear();
|
||||
return Ok((false, String::new()));
|
||||
if !self.is_edit_mode {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
self.command_message.clear();
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(action) = config.get_action_for_key_in_mode(
|
||||
|
||||
Reference in New Issue
Block a user