@@ -37,7 +37,6 @@ static EX: smol::Executor = smol::Executor::new();
3737pub struct Application {
3838 editor: Editor,
3939 prompt: Option<Prompt>,
40− should_close: bool,
4140 terminal: Renderer,
4241}
4342
@@ -299,19 +298,18 @@ impl Application {
299298 terminal,
300299 // TODO; move to state
301300 prompt: None,
302− should_close: false,
303301 };
304302
305303 Ok(app)
306304 }
307305
308306 pub fn set_prompt(&mut self) {
309− // let commands = |input| match input {
310− // "q" => self.should_close = true,
311− // _ => (),
312− // };
313− // let prompt = Prompt::new(|input| None, commands);
314− // self.prompt = Some(prompt);
307+ let commands = |editor: &mut Editor, input: &str| match input {
308+ "q" => editor.should_close = true,
309+ _ => (),
310+ };
311+ let prompt = Prompt::new(|input| None, commands);
312+ self.prompt = Some(prompt);
315313 }
316314
317315 fn render(&mut self) {
@@ -341,12 +339,12 @@ impl Application {
341339 self.render();
342340
343341 loop {
344− // Handle key events
345− if self.should_close {
342+ if self.editor.should_close {
346343 break;
347344 }
348− let mut event = reader.next().await;
349− match event {
345+
346+ // Handle key events
347+ match reader.next().await {
350348 Some(Ok(Event::Resize(width, height))) => {
351349 self.terminal.resize(width, height);
352350
@@ -359,10 +357,16 @@ impl Application {
359357 self.render();
360358 }
361359 Some(Ok(Event::Key(event))) => {
362− // TODO: sequences (`gg`)
363− // TODO: handle count other than 1
364− if let Some(view) = &mut self.editor.view {
360+ // if there's a prompt, it takes priority
361+ if let Some(prompt) = &mut self.prompt {
362+ self.prompt
363+ .as_mut()
364+ .unwrap()
365+ .handle_input(event, &mut self.editor);
366+ } else if let Some(view) = &mut self.editor.view {
365367 let keys = vec![event];
368+ // TODO: sequences (`gg`)
369+ // TODO: handle count other than 1
366370 match view.state.mode() {
367371 Mode::Insert => {
368372 if let Some(command) = keymap[&Mode::Insert].get(&keys) {
@@ -376,9 +380,7 @@ impl Application {
376380 }
377381 view.ensure_cursor_in_view();
378382 }
379− Mode::Command => {
380− self.prompt.as_mut().unwrap().handle_input(event, view);
381− }
383+ Mode::Command => unreachable!(),
382384 mode => {
383385 if let Some(command) = keymap[&mode].get(&keys) {
384386 command(view, 1);
@@ -391,9 +393,7 @@ impl Application {
391393 self.render();
392394 }
393395 }
394− Some(Ok(_)) => {
395− // unhandled event
396− }
396+ Some(Ok(Event::Mouse(_))) => (), // unhandled
397397 Some(Err(x)) => panic!(x),
398398 None => break,
399399 }