aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-16 05:37:12 +0000
committerBlaž Hrastnik2020-10-16 05:37:12 +0000
commit49b4cdb5669b1c572b2b26af4353cb16cb1260f7 (patch)
tree46b8399f87bb9df099e63cb499a6513e5f3e52c8 /helix-view/src
parent49cc6c19244462b80beeac96be0ea0cc5bc1febc (diff)
Refactor command calling.
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs6
-rw-r--r--helix-view/src/prompt.rs12
2 files changed, 11 insertions, 7 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 444e4bf7..c292caed 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -6,11 +6,15 @@ use anyhow::Error;
pub struct Editor {
pub view: Option<View>,
+ pub should_close: bool,
}
impl Editor {
pub fn new() -> Self {
- Self { view: None }
+ Self {
+ view: None,
+ should_close: false,
+ }
}
pub fn open(&mut self, path: PathBuf, size: (u16, u16)) -> Result<(), Error> {
diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs
index b352a386..f0ae44c9 100644
--- a/helix-view/src/prompt.rs
+++ b/helix-view/src/prompt.rs
@@ -1,5 +1,5 @@
use crate::commands;
-use crate::View;
+use crate::{Editor, View};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::string::String;
@@ -7,13 +7,13 @@ pub struct Prompt {
pub buffer: String,
pub cursor_loc: usize,
completion_fn: Box<dyn FnMut(&str) -> Option<Vec<&str>>>,
- callback_fn: Box<dyn FnMut(&str)>,
+ callback_fn: Box<dyn FnMut(&mut Editor, &str)>,
}
impl Prompt {
pub fn new(
completion_fn: impl FnMut(&str) -> Option<Vec<&str>> + 'static,
- callback_fn: impl FnMut(&str) + 'static,
+ callback_fn: impl FnMut(&mut Editor, &str) + 'static,
) -> Prompt {
Prompt {
buffer: String::from(""),
@@ -55,7 +55,7 @@ impl Prompt {
}
}
- pub fn handle_input(&mut self, key_event: KeyEvent, view: &mut View) {
+ pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
match key_event {
KeyEvent {
code: KeyCode::Char(c),
@@ -63,7 +63,7 @@ impl Prompt {
} => self.insert_char(c),
KeyEvent {
code: KeyCode::Esc, ..
- } => commands::normal_mode(view, 1),
+ } => unimplemented!("Exit prompt!"),
KeyEvent {
code: KeyCode::Right,
..
@@ -87,7 +87,7 @@ impl Prompt {
KeyEvent {
code: KeyCode::Enter,
..
- } => (self.callback_fn)(&self.buffer),
+ } => (self.callback_fn)(editor, &self.buffer),
_ => (),
}
}