on master help sign in
move commands and keymap back to terminal.

Command needs to be able to deal with UI. We'll separate it again later on.

commit5103dc96173afaa1c0793db56f60ec1fef1e0fc3 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 10 Dec 2020, 18:13 (6 years ago) parentbe3c021
9 files changed+35−38
Cargo.lock+1 helix-term/Cargo.toml+1 helix-term/src/application.rs+15−30 helix-view/src/commands.rs → helix-term/src/commands.rs+4−2 helix-term/src/compositor.rs+8 helix-view/src/keymap.rs → helix-term/src/keymap.rs+2−2 helix-term/src/main.rs+3 helix-view/src/prompt.rs → helix-term/src/prompt.rs+1−1 helix-view/src/lib.rs−3
Cargo.lock+1
@@ -522,6 +522,7 @@ dependencies = [
522522 "helix-view",
523523 "log",
524524 "num_cpus",
525+ "once_cell",
525526 "smol",
526527 "tui",
527528]
helix-term/Cargo.toml+1
@@ -17,6 +17,7 @@ helix-view = { path = "../helix-view", features = ["term"]}
1717helix-lsp = { path = "../helix-lsp"}
1818
1919anyhow = "1"
20+once_cell = "1.4"
2021
2122smol = "1"
2223num_cpus = "1"
helix-term/src/application.rs+15−30
@@ -1,14 +1,14 @@
1−use clap::ArgMatches as Args;
2−use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
3−use helix_view::{
1+use crate::{
42 commands,
5− document::Mode,
63 keymap::{self, Keymaps},
7− prompt::Prompt,
8− Document, Editor, Theme, View,
94};
5+use clap::ArgMatches as Args;
6+use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
7+
8+use helix_view::{document::Mode, Document, Editor, Theme, View};
109
1110use crate::compositor::{Component, Compositor, EventResult};
11+use crate::prompt::Prompt;
1212
1313use log::{debug, info};
1414
@@ -395,23 +395,16 @@ impl Component for EditorView {
395395 EventResult::Consumed(None)
396396 }
397397 Event::Key(event) => {
398− // if there's a prompt, it takes priority
399− if let Some(prompt) = &mut self.prompt {
400− self.prompt
401− .as_mut()
402− .unwrap()
403− .handle_input(event, &mut self.editor);
404− EventResult::Consumed(None)
405− } else if let Some(view) = self.editor.view_mut() {
398+ if let Some(view) = self.editor.view_mut() {
406399 let keys = vec![event];
407400 // TODO: sequences (`gg`)
408401 // TODO: handle count other than 1
409402 match view.doc.mode() {
410403 Mode::Insert => {
411404 if let Some(command) = self.keymap[&Mode::Insert].get(&keys) {
412− let mut cx = helix_view::commands::Context {
405+ let mut cx = commands::Context {
413406 view,
414− executor: executor,
407+ executor,
415408 count: 1,
416409 };
417410
@@ -421,9 +414,9 @@ impl Component for EditorView {
421414 ..
422415 } = event
423416 {
424− let mut cx = helix_view::commands::Context {
417+ let mut cx = commands::Context {
425418 view,
426− executor: executor,
419+ executor,
427420 count: 1,
428421 };
429422 commands::insert::insert_char(&mut cx, c);
@@ -488,9 +481,9 @@ impl Component for EditorView {
488481
489482 // HAXX: special casing for command mode
490483 } else if let Some(command) = self.keymap[&Mode::Normal].get(&keys) {
491− let mut cx = helix_view::commands::Context {
484+ let mut cx = commands::Context {
492485 view,
493− executor: executor,
486+ executor,
494487 count: 1,
495488 };
496489 command(&mut cx);
@@ -501,9 +494,9 @@ impl Component for EditorView {
501494 }
502495 mode => {
503496 if let Some(command) = self.keymap[&mode].get(&keys) {
504− let mut cx = helix_view::commands::Context {
497+ let mut cx = commands::Context {
505498 view,
506− executor: executor,
499+ executor,
507500 count: 1,
508501 };
509502 command(&mut cx);
@@ -530,13 +523,6 @@ impl Component for EditorView {
530523 let theme_ref = unsafe { &*(&self.editor.theme as *const Theme) };
531524 if let Some(view) = self.editor.view_mut() {
532525 renderer.render_view(view, viewport, theme_ref);
533− if let Some(prompt) = &self.prompt {
534− if prompt.should_close {
535− self.prompt = None;
536− } else {
537− renderer.render_prompt(view, prompt, theme_ref);
538− }
539− }
540526 }
541527
542528 // TODO: drop unwrap
@@ -562,7 +548,6 @@ impl<'a> Application<'a> {
562548 renderer,
563549 // TODO; move to state
564550 compositor,
565− prompt: None,
566551
567552 executor,
568553 language_server,
helix-view/src/commands.rs → helix-term/src/commands.rsrenamed+4−2
@@ -6,11 +6,13 @@ use helix_core::{
66 state::{Direction, Granularity, State},
77 ChangeSet, Range, Selection, Tendril, Transaction,
88};
9+
910use once_cell::sync::Lazy;
1011
11−use crate::{
12+use crate::prompt::Prompt;
13+
14+use helix_view::{
1215 document::Mode,
13− prompt::Prompt,
1416 view::{View, PADDING},
1517};
1618
helix-term/src/compositor.rs+8
@@ -20,6 +20,14 @@ use tui::buffer::Buffer as Surface;
2020
2121pub(crate) type Callback = Box<dyn Fn(&mut Compositor)>;
2222
23+// --> EventResult should have a callback that takes a context with methods like .popup(),
24+// .prompt() etc. That way we can abstract it from the renderer.
25+// Q: How does this interact with popups where we need to be able to specify the rendering of the
26+// popup?
27+// A: It could just take a textarea.
28+//
29+// If Compositor was specified in the callback that's then problematic because of
30+
2331// Cursive-inspired
2432pub(crate) enum EventResult {
2533 Ignored,
helix-view/src/keymap.rs → helix-term/src/keymap.rsrenamed+2−2
@@ -1,6 +1,6 @@
11use crate::commands::{self, Command};
2−use crate::document::Mode;
32use helix_core::hashmap;
3+use helix_view::document::Mode;
44use std::collections::HashMap;
55
66// Kakoune-inspired:
@@ -87,7 +87,7 @@ use std::collections::HashMap;
8787// gr = goto reference
8888// }
8989
90−#[cfg(feature = "term")]
90+// #[cfg(feature = "term")]
9191pub use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
9292
9393// TODO: could be trie based
helix-term/src/main.rs+3
@@ -1,7 +1,10 @@
11#![allow(unused)]
22
33mod application;
4+mod commands;
45mod compositor;
6+mod keymap;
7+mod prompt;
58
69use application::Application;
710
helix-view/src/prompt.rs → helix-term/src/prompt.rsrenamed+1−1
@@ -80,7 +80,7 @@ impl Prompt {
8080 self.completion_selection_index = None;
8181 }
8282
83− pub fn handle_input(&mut self, key_event: KeyEvent, editor: &mut Editor) {
83+ pub fn handle_event(&mut self, key_event: KeyEvent, editor: &mut Editor) {
8484 match key_event {
8585 KeyEvent {
8686 code: KeyCode::Char(c),
helix-view/src/lib.rs−3
@@ -1,8 +1,5 @@
1−pub mod commands;
21pub mod document;
32pub mod editor;
4−pub mod keymap;
5−pub mod prompt;
63pub mod theme;
74pub mod view;
85