Unnamed repository; edit this file 'description' to name the repository.
move commands and keymap back to terminal.
Command needs to be able to deal with UI. We'll separate it again later on.
Blaž Hrastnik 2020-12-10
parent be3c021 · commit 5103dc9
-rw-r--r--Cargo.lock1
-rw-r--r--helix-term/Cargo.toml1
-rw-r--r--helix-term/src/application.rs45
-rw-r--r--helix-term/src/commands.rs (renamed from helix-view/src/commands.rs)6
-rw-r--r--helix-term/src/compositor.rs8
-rw-r--r--helix-term/src/keymap.rs (renamed from helix-view/src/keymap.rs)4
-rw-r--r--helix-term/src/main.rs3
-rw-r--r--helix-term/src/prompt.rs (renamed from helix-view/src/prompt.rs)2
-rw-r--r--helix-view/src/lib.rs3
9 files changed, 35 insertions, 38 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a3e93bd7..331934f8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -522,6 +522,7 @@ dependencies = [
"helix-view",
"log",
"num_cpus",
+ "once_cell",
"smol",
"tui",
]
diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml
index c1560ee7..b8eea7c2 100644
--- a/helix-term/Cargo.toml
+++ b/helix-term/Cargo.toml
@@ -17,6 +17,7 @@ helix-view = { path = "../helix-view", features = ["term"]}
helix-lsp = { path = "../helix-lsp"}
anyhow = "1"
+once_cell = "1.4"
smol = "1"
num_cpus = "1"
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 506735e8..8c454b5d 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -1,14 +1,14 @@
-use clap::ArgMatches as Args;
-use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
-use helix_view::{
+use crate::{
commands,
- document::Mode,
keymap::{self, Keymaps},
- prompt::Prompt,
- Document, Editor, Theme, View,
};
+use clap::ArgMatches as Args;
+use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
+
+use helix_view::{document::Mode, Document, Editor, Theme, View};
use crate::compositor::{Component, Compositor, EventResult};
+use crate::prompt::Prompt;
use log::{debug, info};
@@ -395,23 +395,16 @@ impl Component for EditorView {
EventResult::Consumed(None)
}
Event::Key(event) => {
- // if there's a prompt, it takes priority
- if let Some(prompt) = &mut self.prompt {
- self.prompt
- .as_mut()
- .unwrap()
- .handle_input(event, &mut self.editor);
- EventResult::Consumed(None)
- } else if let Some(view) = self.editor.view_mut() {
+ if let Some(view) = self.editor.view_mut() {
let keys = vec![event];
// TODO: sequences (`gg`)
// TODO: handle count other than 1
match view.doc.mode() {
Mode::Insert => {
if let Some(command) = self.keymap[&Mode::Insert].get(&keys) {
- let mut cx = helix_view::commands::Context {
+ let mut cx = commands::Context {
view,
- executor: executor,
+ executor,
count: 1,
};
@@ -421,9 +414,9 @@ impl Component for EditorView {
..
} = event
{
- let mut cx = helix_view::commands::Context {
+ let mut cx = commands::Context {
view,
- executor: executor,
+ executor,
count: 1,
};
commands::insert::insert_char(&mut cx, c);
@@ -488,9 +481,9 @@ impl Component for EditorView {
// HAXX: special casing for command mode
} else if let Some(command) = self.keymap[&Mode::Normal].get(&keys) {
- let mut cx = helix_view::commands::Context {
+ let mut cx = commands::Context {
view,
- executor: executor,
+ executor,
count: 1,
};
command(&mut cx);
@@ -501,9 +494,9 @@ impl Component for EditorView {
}
mode => {
if let Some(command) = self.keymap[&mode].get(&keys) {
- let mut cx = helix_view::commands::Context {
+ let mut cx = commands::Context {
view,
- executor: executor,
+ executor,
count: 1,
};
command(&mut cx);
@@ -530,13 +523,6 @@ impl Component for EditorView {
let theme_ref = unsafe { &*(&self.editor.theme as *const Theme) };
if let Some(view) = self.editor.view_mut() {
renderer.render_view(view, viewport, theme_ref);
- if let Some(prompt) = &self.prompt {
- if prompt.should_close {
- self.prompt = None;
- } else {
- renderer.render_prompt(view, prompt, theme_ref);
- }
- }
}
// TODO: drop unwrap
@@ -562,7 +548,6 @@ impl<'a> Application<'a> {
renderer,
// TODO; move to state
compositor,
- prompt: None,
executor,
language_server,
diff --git a/helix-view/src/commands.rs b/helix-term/src/commands.rs
index c135a3da..a791f243 100644
--- a/helix-view/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -6,11 +6,13 @@ use helix_core::{
state::{Direction, Granularity, State},
ChangeSet, Range, Selection, Tendril, Transaction,
};
+
use once_cell::sync::Lazy;
-use crate::{
+use crate::prompt::Prompt;
+
+use helix_view::{
document::Mode,
- prompt::Prompt,
view::{View, PADDING},
};
diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs
index f859f947..158a8b28 100644
--- a/helix-term/src/compositor.rs
+++ b/helix-term/src/compositor.rs
@@ -20,6 +20,14 @@ use tui::buffer::Buffer as Surface;
pub(crate) type Callback = Box<dyn Fn(&mut Compositor)>;
+// --> EventResult should have a callback that takes a context with methods like .popup(),
+// .prompt() etc. That way we can abstract it from the renderer.
+// Q: How does this interact with popups where we need to be able to specify the rendering of the
+// popup?
+// A: It could just take a textarea.
+//
+// If Compositor was specified in the callback that's then problematic because of
+
// Cursive-inspired
pub(crate) enum EventResult {
Ignored,
diff --git a/helix-view/src/keymap.rs b/helix-term/src/keymap.rs
index c815911e..af46f7a4 100644
--- a/helix-view/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -1,6 +1,6 @@
use crate::commands::{self, Command};
-use crate::document::Mode;
use helix_core::hashmap;
+use helix_view::document::Mode;
use std::collections::HashMap;
// Kakoune-inspired:
@@ -87,7 +87,7 @@ use std::collections::HashMap;
// gr = goto reference
// }
-#[cfg(feature = "term")]
+// #[cfg(feature = "term")]
pub use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
// TODO: could be trie based
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index a43aebd8..92ab10c2 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -1,7 +1,10 @@
#![allow(unused)]
mod application;
+mod commands;
mod compositor;
+mod keymap;
+mod prompt;
use application::Application;
diff --git a/helix-view/src/prompt.rs b/helix-term/src/prompt.rs
index e2a9c80d..4a39f2ec 100644
--- a/helix-view/src/prompt.rs
+++ b/helix-term/src/prompt.rs
@@ -80,7 +80,7 @@ impl Prompt {
self.completion_selection_index = None;
}
- pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
+ pub fn handle_event(&mut self, key_event: KeyEvent, editor: &mut Editor) {
match key_event {
KeyEvent {
code: KeyCode::Char(c),
diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs
index 3b923744..f28c8116 100644
--- a/helix-view/src/lib.rs
+++ b/helix-view/src/lib.rs
@@ -1,8 +1,5 @@
-pub mod commands;
pub mod document;
pub mod editor;
-pub mod keymap;
-pub mod prompt;
pub mod theme;
pub mod view;