on master help sign in
move commands and keymap back to terminal.
5103dc9Blaž Hrastnik
Cargo.lock+1
@@ -522,6 +522,7 @@ dependencies = [
522 "helix-view",
522 "helix-view",
523 "log",
523 "log",
524 "num_cpus",
524 "num_cpus",
525+ "once_cell",
525 "smol",
526 "smol",
526 "tui",
527 "tui",
527]
528]
helix-term/Cargo.toml+1
@@ -17,6 +17,7 @@ helix-view = { path = "../helix-view", features = ["term"]}
17helix-lsp = { path = "../helix-lsp"}
17helix-lsp = { path = "../helix-lsp"}
18
18
19anyhow = "1"
19anyhow = "1"
20+once_cell = "1.4"
20
21
21smol = "1"
22smol = "1"
22num_cpus = "1"
23num_cpus = "1"
helix-term/src/application.rs+15−30
@@ -1,14 +1,14 @@
1−use clap::ArgMatches as Args;
1+use crate::{
2−use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
3−use helix_view::{
4 commands,
2 commands,
5− document::Mode,
6 keymap::{self, Keymaps},
3 keymap::{self, Keymaps},
7− prompt::Prompt,
8− Document, Editor, Theme, View,
9};
4};
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};
10
9
11use crate::compositor::{Component, Compositor, EventResult};
10use crate::compositor::{Component, Compositor, EventResult};
11+use crate::prompt::Prompt;
12
12
13use log::{debug, info};
13use log::{debug, info};
14
14
@@ -395,23 +395,16 @@ impl Component for EditorView {
395 EventResult::Consumed(None)
395 EventResult::Consumed(None)
396 }
396 }
397 Event::Key(event) => {
397 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() {
406 let keys = vec![event];
399 let keys = vec![event];
407 // TODO: sequences (`gg`)
400 // TODO: sequences (`gg`)
408 // TODO: handle count other than 1
401 // TODO: handle count other than 1
409 match view.doc.mode() {
402 match view.doc.mode() {
410 Mode::Insert => {
403 Mode::Insert => {
411 if let Some(command) = self.keymap[&Mode::Insert].get(&keys) {
404 if let Some(command) = self.keymap[&Mode::Insert].get(&keys) {
412− let mut cx = helix_view::commands::Context {
405+ let mut cx = commands::Context {
413 view,
406 view,
414− executor: executor,
407+ executor,
415 count: 1,
408 count: 1,
416 };
409 };
417
410
@@ -421,9 +414,9 @@ impl Component for EditorView {
421 ..
414 ..
422 } = event
415 } = event
423 {
416 {
424− let mut cx = helix_view::commands::Context {
417+ let mut cx = commands::Context {
425 view,
418 view,
426− executor: executor,
419+ executor,
427 count: 1,
420 count: 1,
428 };
421 };
429 commands::insert::insert_char(&mut cx, c);
422 commands::insert::insert_char(&mut cx, c);
@@ -488,9 +481,9 @@ impl Component for EditorView {
488
481
489 // HAXX: special casing for command mode
482 // HAXX: special casing for command mode
490 } else if let Some(command) = self.keymap[&Mode::Normal].get(&keys) {
483 } 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 {
492 view,
485 view,
493− executor: executor,
486+ executor,
494 count: 1,
487 count: 1,
495 };
488 };
496 command(&mut cx);
489 command(&mut cx);
@@ -501,9 +494,9 @@ impl Component for EditorView {
501 }
494 }
502 mode => {
495 mode => {
503 if let Some(command) = self.keymap[&mode].get(&keys) {
496 if let Some(command) = self.keymap[&mode].get(&keys) {
504− let mut cx = helix_view::commands::Context {
497+ let mut cx = commands::Context {
505 view,
498 view,
506− executor: executor,
499+ executor,
507 count: 1,
500 count: 1,
508 };
501 };
509 command(&mut cx);
502 command(&mut cx);
@@ -530,13 +523,6 @@ impl Component for EditorView {
530 let theme_ref = unsafe { &*(&self.editor.theme as *const Theme) };
523 let theme_ref = unsafe { &*(&self.editor.theme as *const Theme) };
531 if let Some(view) = self.editor.view_mut() {
524 if let Some(view) = self.editor.view_mut() {
532 renderer.render_view(view, viewport, theme_ref);
525 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− }
540 }
526 }
541
527
542 // TODO: drop unwrap
528 // TODO: drop unwrap
@@ -562,7 +548,6 @@ impl<'a> Application<'a> {
562 renderer,
548 renderer,
563 // TODO; move to state
549 // TODO; move to state
564 compositor,
550 compositor,
565− prompt: None,
566
551
567 executor,
552 executor,
568 language_server,
553 language_server,
helix-view/src/commands.rs → helix-term/src/commands.rsrenamed+4−2
@@ -6,11 +6,13 @@ use helix_core::{
6 state::{Direction, Granularity, State},
6 state::{Direction, Granularity, State},
7 ChangeSet, Range, Selection, Tendril, Transaction,
7 ChangeSet, Range, Selection, Tendril, Transaction,
8};
8};
9+
9use once_cell::sync::Lazy;
10use once_cell::sync::Lazy;
10
11
11−use crate::{
12+use crate::prompt::Prompt;
13+
14+use helix_view::{
12 document::Mode,
15 document::Mode,
13− prompt::Prompt,
14 view::{View, PADDING},
16 view::{View, PADDING},
15};
17};
16
18
helix-term/src/compositor.rs+8
@@ -20,6 +20,14 @@ use tui::buffer::Buffer as Surface;
20
20
21pub(crate) type Callback = Box<dyn Fn(&mut Compositor)>;
21pub(crate) type Callback = Box<dyn Fn(&mut Compositor)>;
22
22
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+
23// Cursive-inspired
31// Cursive-inspired
24pub(crate) enum EventResult {
32pub(crate) enum EventResult {
25 Ignored,
33 Ignored,
helix-view/src/keymap.rs → helix-term/src/keymap.rsrenamed+2−2
@@ -1,6 +1,6 @@
1use crate::commands::{self, Command};
1use crate::commands::{self, Command};
2−use crate::document::Mode;
3use helix_core::hashmap;
2use helix_core::hashmap;
3+use helix_view::document::Mode;
4use std::collections::HashMap;
4use std::collections::HashMap;
5
5
6// Kakoune-inspired:
6// Kakoune-inspired:
@@ -87,7 +87,7 @@ use std::collections::HashMap;
87// gr = goto reference
87// gr = goto reference
88// }
88// }
89
89
90−#[cfg(feature = "term")]
90+// #[cfg(feature = "term")]
91pub use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
91pub use crossterm::event::{KeyCode, KeyEvent as Key, KeyModifiers as Modifiers};
92
92
93// TODO: could be trie based
93// TODO: could be trie based
helix-term/src/main.rs+3
@@ -1,7 +1,10 @@
1#![allow(unused)]
1#![allow(unused)]
2
2
3mod application;
3mod application;
4+mod commands;
4mod compositor;
5mod compositor;
6+mod keymap;
7+mod prompt;
5
8
6use application::Application;
9use application::Application;
7
10
helix-view/src/prompt.rs → helix-term/src/prompt.rsrenamed+1−1
@@ -80,7 +80,7 @@ impl Prompt {
80 self.completion_selection_index = None;
80 self.completion_selection_index = None;
81 }
81 }
82
82
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) {
84 match key_event {
84 match key_event {
85 KeyEvent {
85 KeyEvent {
86 code: KeyCode::Char(c),
86 code: KeyCode::Char(c),
helix-view/src/lib.rs−3
@@ -1,8 +1,5 @@
1−pub mod commands;
2pub mod document;
1pub mod document;
3pub mod editor;
2pub mod editor;
4−pub mod keymap;
5−pub mod prompt;
6pub mod theme;
3pub mod theme;
7pub mod view;
4pub mod view;
8
5