aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/editor.rs
diff options
context:
space:
mode:
authorMichael Davis2022-10-03 15:14:57 +0000
committerGitHub2022-10-03 15:14:57 +0000
commit6cca7375ec1965e61c791bbe738c617ea43c6dce (patch)
treeb53f48f9436e39b1efea8e1cb2df118acb2c7787 /helix-term/src/ui/editor.rs
parent9124c231f426318e970c62647c1ddabed3c9a389 (diff)
Automatically track pseudo-pending text (#4077)
This change automatically tracks pending text for for commands which use on-next-key callbacks. For example, `t` will await the next key event and "t" will be shown in the bottom right-hand corner to show that we're in a pending state. Previously, the text for these on-next-key commands needed to be hard-coded into the command definition which had some drawbacks: * It was easy to forget to write and clear the pending text. * If a command was remapped in a custom config, the pending text would still show the old key. With this change, pending text is automatically tracked based on the key events that lead to the command being executed. This works even when the command is remapped in config and when the on-next-key callback is nested under some key sequence (for example `mi`).
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r--helix-term/src/ui/editor.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index e5dc3c95..97639ff2 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -33,6 +33,7 @@ use super::statusline;
pub struct EditorView {
pub keymaps: Keymaps,
on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
+ pseudo_pending: Vec<KeyEvent>,
last_insert: (commands::MappableCommand, Vec<InsertEvent>),
pub(crate) completion: Option<Completion>,
spinners: ProgressSpinners,
@@ -56,6 +57,7 @@ impl EditorView {
Self {
keymaps,
on_next_key: None,
+ pseudo_pending: Vec::new(),
last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
completion: None,
spinners: ProgressSpinners::default(),
@@ -839,6 +841,7 @@ impl EditorView {
event: KeyEvent,
) -> Option<KeymapResult> {
let mut last_mode = mode;
+ self.pseudo_pending.extend(self.keymaps.pending());
let key_result = self.keymaps.get(mode, event);
cxt.editor.autoinfo = self.keymaps.sticky().map(|node| node.infobox());
@@ -1316,6 +1319,11 @@ impl Component for EditorView {
}
self.on_next_key = cx.on_next_key_callback.take();
+ match self.on_next_key {
+ Some(_) => self.pseudo_pending.push(key),
+ None => self.pseudo_pending.clear(),
+ }
+
// appease borrowck
let callback = cx.callback.take();
@@ -1416,8 +1424,8 @@ impl Component for EditorView {
for key in self.keymaps.pending() {
disp.push_str(&key.key_sequence_format());
}
- if let Some(pseudo_pending) = &cx.editor.pseudo_pending {
- disp.push_str(pseudo_pending.as_str())
+ for key in &self.pseudo_pending {
+ disp.push_str(&key.key_sequence_format());
}
let style = cx.editor.theme.get("ui.text");
let macro_width = if cx.editor.macro_recording.is_some() {