Skip to content

Commit

Permalink
fix tab and filter on backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedwen committed Nov 26, 2023
1 parent 1c633e6 commit 86841db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
20 changes: 13 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}
}
30 changes: 13 additions & 17 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 86841db

Please sign in to comment.