aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/ui/editor.rs')
-rw-r--r--helix-term/src/ui/editor.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 63b3e277..07107c9e 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -11,10 +11,7 @@ use helix_core::{
syntax::{self, HighlightEvent},
Position, Range,
};
-use helix_view::{
- document::{IndentStyle, Mode},
- Document, Editor, Theme, View,
-};
+use helix_view::{document::Mode, Document, Editor, Theme, View};
use std::borrow::Cow;
use crossterm::{
@@ -30,7 +27,7 @@ use tui::{
};
pub struct EditorView {
- keymap: Keymaps,
+ keymaps: Keymaps,
on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
last_insert: (commands::Command, Vec<KeyEvent>),
completion: Option<Completion>,
@@ -40,16 +37,16 @@ const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
impl Default for EditorView {
fn default() -> Self {
- Self::new()
+ Self::new(Keymaps::default())
}
}
impl EditorView {
- pub fn new() -> Self {
+ pub fn new(keymaps: Keymaps) -> Self {
Self {
- keymap: keymap::default(),
+ keymaps,
on_next_key: None,
- last_insert: (commands::normal_mode, Vec::new()),
+ last_insert: (commands::Command::normal_mode, Vec::new()),
completion: None,
}
}
@@ -546,8 +543,8 @@ impl EditorView {
}
fn insert_mode(&self, cx: &mut commands::Context, event: KeyEvent) {
- if let Some(command) = self.keymap[&Mode::Insert].get(&event) {
- command(cx);
+ if let Some(command) = self.keymaps[&Mode::Insert].get(&event) {
+ command.execute(cx);
} else if let KeyEvent {
code: KeyCode::Char(ch),
..
@@ -568,7 +565,7 @@ impl EditorView {
// special handling for repeat operator
key!('.') => {
// first execute whatever put us into insert mode
- (self.last_insert.0)(cxt);
+ self.last_insert.0.execute(cxt);
// then replay the inputs
for key in &self.last_insert.1 {
self.insert_mode(cxt, *key)
@@ -584,8 +581,8 @@ impl EditorView {
// set the register
cxt.selected_register = cxt.editor.selected_register.take();
- if let Some(command) = self.keymap[&mode].get(&event) {
- command(cxt);
+ if let Some(command) = self.keymaps[&mode].get(&event) {
+ command.execute(cxt);
}
}
}
@@ -699,7 +696,7 @@ 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 = self.keymap[&mode][&key];
+ self.last_insert.0 = self.keymaps[&mode][&key];
self.last_insert.1.clear();
}
(Mode::Insert, Mode::Normal) => {