summaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorGokul Soumya2021-09-05 03:55:13 +0000
committerGitHub2021-09-05 03:55:13 +0000
commit183dcce992d7c5b2065a93c5835d61e8ee4e9f05 (patch)
tree6782bb4f70ead97db989ddca423e99d42b5e1d5b /helix-term/src/ui
parent99a753a5797d38885560e9026b86952615032556 (diff)
Add a sticky mode for keymaps (#635)
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/editor.rs36
1 files changed, 20 insertions, 16 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 4b9c56e7..e8cd40cf 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -2,7 +2,7 @@ use crate::{
commands,
compositor::{Component, Context, EventResult},
key,
- keymap::{KeymapResult, Keymaps},
+ keymap::{KeymapResult, KeymapResultKind, Keymaps},
ui::{Completion, ProgressSpinners},
};
@@ -638,7 +638,7 @@ impl EditorView {
/// Handle events by looking them up in `self.keymaps`. Returns None
/// if event was handled (a command was executed or a subkeymap was
- /// activated). Only KeymapResult::{NotFound, Cancelled} is returned
+ /// activated). Only KeymapResultKind::{NotFound, Cancelled} is returned
/// otherwise.
fn handle_keymap_event(
&mut self,
@@ -647,29 +647,32 @@ impl EditorView {
event: KeyEvent,
) -> Option<KeymapResult> {
self.autoinfo = None;
- match self.keymaps.get_mut(&mode).unwrap().get(event) {
- KeymapResult::Matched(command) => command.execute(cxt),
- KeymapResult::Pending(node) => self.autoinfo = Some(node.into()),
- k @ KeymapResult::NotFound | k @ KeymapResult::Cancelled(_) => return Some(k),
+ let key_result = self.keymaps.get_mut(&mode).unwrap().get(event);
+ self.autoinfo = key_result.sticky.map(|node| node.infobox());
+
+ match &key_result.kind {
+ KeymapResultKind::Matched(command) => command.execute(cxt),
+ KeymapResultKind::Pending(node) => self.autoinfo = Some(node.infobox()),
+ KeymapResultKind::NotFound | KeymapResultKind::Cancelled(_) => return Some(key_result),
}
None
}
fn insert_mode(&mut self, cx: &mut commands::Context, event: KeyEvent) {
if let Some(keyresult) = self.handle_keymap_event(Mode::Insert, cx, event) {
- match keyresult {
- KeymapResult::NotFound => {
+ match keyresult.kind {
+ KeymapResultKind::NotFound => {
if let Some(ch) = event.char() {
commands::insert::insert_char(cx, ch)
}
}
- KeymapResult::Cancelled(pending) => {
+ KeymapResultKind::Cancelled(pending) => {
for ev in pending {
match ev.char() {
Some(ch) => commands::insert::insert_char(cx, ch),
None => {
- if let KeymapResult::Matched(command) =
- self.keymaps.get_mut(&Mode::Insert).unwrap().get(ev)
+ if let KeymapResultKind::Matched(command) =
+ self.keymaps.get_mut(&Mode::Insert).unwrap().get(ev).kind
{
command.execute(cx);
}
@@ -976,11 +979,12 @@ impl Component for EditorView {
// how we entered insert mode is important, and we should track that so
// we can repeat the side effect.
- self.last_insert.0 = match self.keymaps.get_mut(&mode).unwrap().get(key) {
- KeymapResult::Matched(command) => command,
- // FIXME: insert mode can only be entered through single KeyCodes
- _ => unimplemented!(),
- };
+ self.last_insert.0 =
+ match self.keymaps.get_mut(&mode).unwrap().get(key).kind {
+ KeymapResultKind::Matched(command) => command,
+ // FIXME: insert mode can only be entered through single KeyCodes
+ _ => unimplemented!(),
+ };
self.last_insert.1.clear();
}
(Mode::Insert, Mode::Normal) => {