diff --git a/src/app.rs b/src/app.rs index aac1166..ccee4d5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -23,10 +23,18 @@ impl AppContext { pub fn target(&self) -> Option<&command::Command> { self.list.filtered.get(self.current_index) } - pub fn filter(&mut self) { + fn filter(&mut self) { self.list.filter(&self.input, &self.config.history); info!("{}", self.list); } + pub fn pop_and_filter(&mut self) { + self.input.pop(); + self.filter() + } + pub fn append_and_filter(&mut self, input: &str) { + self.input.push_str(input); + self.filter() + } } impl App { @@ -56,13 +64,11 @@ impl App { let mut menu_shell = menu::Shell::new(app_context, globals, qh); - // We don't draw immediately, the configure will notify us when to first draw. - loop { + // Run the loop until exit + while !menu_shell.about_to_exit() { event_queue.blocking_dispatch(&mut menu_shell)?; - - if menu_shell.about_to_exit() { - return Ok(()); - } } + + Ok(()) } } diff --git a/src/menu.rs b/src/menu.rs index 42a8e7c..574227c 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -356,7 +356,7 @@ impl Shell { .wl_surface() .frame(qh, self.layer.wl_surface().clone()); - // Attach and commit to present. + // Attach and commit to present buffer .attach_to(self.layer.wl_surface()) .expect("buffer attach"); @@ -371,19 +371,18 @@ impl Shell { } Keysym::BackSpace => { // pop one char - self.context.input.pop(); + self.context.pop_and_filter(); } Keysym::Tab => { - if self.context.modifiers.shift { - if self.context.current_index > 0 { - // shift index left - self.context.current_index -= 1; - } else { - if self.context.current_index < self.context.list.filtered_len() { - // shift index right - self.context.current_index += 1; - } - } + if self.context.current_index < self.context.list.filtered_len() { + // shift index right + self.context.current_index += 1; + } + } + Keysym::ISO_Left_Tab => { + if self.context.current_index > 0 { + // shift index left + self.context.current_index -= 1; } } Keysym::Return => { @@ -411,11 +410,8 @@ impl Shell { Some(txt) => { debug!(" -> Received text `{}`", txt); - // append key to filter - self.context.input.push_str(txt.as_str()); - - // apply the filter - self.context.filter(); + // append and apply the filter + self.context.append_and_filter(txt.as_str()); // reset current index self.context.current_index = 0;