From bea80dbfe722c7bb13e19665ddbadea03b8b6293 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 17 May 2021 16:58:19 +0530 Subject: implement reverse cycle through completions --- src/app.rs | 5 ++++- src/command.rs | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index aba71f8..266c28b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1042,7 +1042,10 @@ impl<'ctx> AppState<'ctx> { Keycode::Up => self.command_box.hist_prev(), Keycode::Down => self.command_box.hist_next(), Keycode::Return => self.eval_command(), - Keycode::Tab => self.command_box.complete_next(&self.lisp_env), + Keycode::Tab if keymod == Mod::LSHIFTMOD => { + self.command_box.complete(&self.lisp_env, true) + } + Keycode::Tab => self.command_box.complete(&self.lisp_env, false), Keycode::Escape => { self.command_box.clear(); self.message.text.clear(); diff --git a/src/command.rs b/src/command.rs index 26aeb05..6e9f900 100644 --- a/src/command.rs +++ b/src/command.rs @@ -224,14 +224,14 @@ impl CommandBox { self.invalidate_completions(); } - pub fn complete_next(&mut self, env_list: &[Environment]) { + pub fn complete(&mut self, env_list: &[Environment], reverse: bool) { let c = self.cursor; // completions exist, fill with next completion if let Some(cs) = &mut self.completions { self.cursor = cs.trigger_idx; let prev_len = cs.get().len(); // skips over the first empty completion - let new_insertion = cs.next(); + let new_insertion = if reverse { cs.prev() } else { cs.next() }; self.text = format!( "{}{}{}", &self.text[..self.cursor], @@ -249,7 +249,7 @@ impl CommandBox { .map(|&s| s.to_owned()) .collect(), )); - self.complete_next(env_list) + self.complete(env_list, reverse) } } } -- cgit v1.2.3