@@ -37,7 +37,6 @@ static EX: smol::Executor = smol::Executor::new();
37pub struct Application {
37pub struct Application {
38 editor: Editor,
38 editor: Editor,
39 prompt: Option<Prompt>,
39 prompt: Option<Prompt>,
41 terminal: Renderer,
40 terminal: Renderer,
@@ -299,19 +298,18 @@ impl Application {
299 terminal,
298 terminal,
300 // TODO; move to state
299 // TODO; move to state
301 prompt: None,
300 prompt: None,
302− should_close: false,
308 pub fn set_prompt(&mut self) {
306 pub fn set_prompt(&mut self) {
309− // let commands = |input| match input {
307+ let commands = |editor: &mut Editor, input: &str| match input {
310− // "q" => self.should_close = true,
308+ "q" => editor.should_close = true,
311− // _ => (),
309+ _ => (),
313− // let prompt = Prompt::new(|input| None, commands);
311+ let prompt = Prompt::new(|input| None, commands);
314− // self.prompt = Some(prompt);
312+ self.prompt = Some(prompt);
317 fn render(&mut self) {
315 fn render(&mut self) {
@@ -341,12 +339,12 @@ impl Application {
341 self.render();
339 self.render();
344− // Handle key events
345− if self.should_close {
342+ if self.editor.should_close {
346+ // Handle key events
348− let mut event = reader.next().await;
347+ match reader.next().await {
350 Some(Ok(Event::Resize(width, height))) => {
348 Some(Ok(Event::Resize(width, height))) => {
351 self.terminal.resize(width, height);
349 self.terminal.resize(width, height);
@@ -359,10 +357,16 @@ impl Application {
359 self.render();
357 self.render();
361 Some(Ok(Event::Key(event))) => {
359 Some(Ok(Event::Key(event))) => {
362− // TODO: sequences (`gg`)
360+ // if there's a prompt, it takes priority
363− // TODO: handle count other than 1
361+ if let Some(prompt) = &mut self.prompt {
365+ .handle_input(event, &mut self.editor);
364− if let Some(view) = &mut self.editor.view {
366+ } else if let Some(view) = &mut self.editor.view {
365 let keys = vec![event];
367 let keys = vec![event];
368+ // TODO: sequences (`gg`)
369+ // TODO: handle count other than 1
366 match view.state.mode() {
370 match view.state.mode() {
367 Mode::Insert => {
371 Mode::Insert => {
368 if let Some(command) = keymap[&Mode::Insert].get(&keys) {
372 if let Some(command) = keymap[&Mode::Insert].get(&keys) {
@@ -376,9 +380,7 @@ impl Application {
377 view.ensure_cursor_in_view();
381 view.ensure_cursor_in_view();
379− Mode::Command => {
383+ Mode::Command => unreachable!(),
380− self.prompt.as_mut().unwrap().handle_input(event, view);
382 mode => {
384 mode => {
383 if let Some(command) = keymap[&mode].get(&keys) {
385 if let Some(command) = keymap[&mode].get(&keys) {
384 command(view, 1);
386 command(view, 1);
@@ -391,9 +393,7 @@ impl Application {
391 self.render();
393 self.render();
395− // unhandled event
396+ Some(Ok(Event::Mouse(_))) => (), // unhandled
397 Some(Err(x)) => panic!(x),
397 Some(Err(x)) => panic!(x),
398 None => break,
398 None => break,