summaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorOmnikar2021-12-12 12:16:48 +0000
committerGitHub2021-12-12 12:16:48 +0000
commite91d357fae04766b9781fe51a0809d35175fe1cf (patch)
tree338045ab80409343359b2bd7d980beb083843ff8 /helix-view/src
parent3156577fbf1a97e07e90e11b51c66155f122c3b7 (diff)
Macros (#1234)
* Macros WIP `helix_term::compositor::Callback` changed to take a `&mut Context` as a parameter for use by `play_macro` * Default to `@` register for macros * Import `KeyEvent` * Special-case shift-tab -> backtab in `KeyEvent` conversion * Move key recording to the compositor * Add comment * Add persistent display of macro recording status When macro recording is active, the pending keys display will be shifted 3 characters left, and the register being recorded to will be displayed between brackets — e.g., `[@]` — right of the pending keys display. * Fix/add documentation
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs3
-rw-r--r--helix-view/src/input.rs20
2 files changed, 23 insertions, 0 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 9034d12c..dcbcbe4f 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -2,6 +2,7 @@ use crate::{
clipboard::{get_clipboard_provider, ClipboardProvider},
document::SCRATCH_BUFFER_NAME,
graphics::{CursorKind, Rect},
+ input::KeyEvent,
theme::{self, Theme},
tree::{self, Tree},
Document, DocumentId, View, ViewId,
@@ -160,6 +161,7 @@ pub struct Editor {
pub count: Option<std::num::NonZeroUsize>,
pub selected_register: Option<char>,
pub registers: Registers,
+ pub macro_recording: Option<(char, Vec<KeyEvent>)>,
pub theme: Theme,
pub language_servers: helix_lsp::Registry,
pub clipboard_provider: Box<dyn ClipboardProvider>,
@@ -203,6 +205,7 @@ impl Editor {
documents: BTreeMap::new(),
count: None,
selected_register: None,
+ macro_recording: None,
theme: theme_loader.default(),
language_servers,
syn_loader,
diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs
index b207c3ed..92caa517 100644
--- a/helix-view/src/input.rs
+++ b/helix-view/src/input.rs
@@ -234,6 +234,26 @@ impl From<crossterm::event::KeyEvent> for KeyEvent {
}
}
+#[cfg(feature = "term")]
+impl From<KeyEvent> for crossterm::event::KeyEvent {
+ fn from(KeyEvent { code, modifiers }: KeyEvent) -> Self {
+ if code == KeyCode::Tab && modifiers.contains(KeyModifiers::SHIFT) {
+ // special case for Shift-Tab -> BackTab
+ let mut modifiers = modifiers;
+ modifiers.remove(KeyModifiers::SHIFT);
+ crossterm::event::KeyEvent {
+ code: crossterm::event::KeyCode::BackTab,
+ modifiers: modifiers.into(),
+ }
+ } else {
+ crossterm::event::KeyEvent {
+ code: code.into(),
+ modifiers: modifiers.into(),
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;