aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-05-17 12:28:19 +0100
committerAkshay <[email protected]>2021-05-17 12:28:19 +0100
commitbea80dbfe722c7bb13e19665ddbadea03b8b6293 (patch)
treec7685af23965cfaeb19969291d1d883bffc83039 /src
parentd2cc31ee49d673f343ce5089071ef3628c3cdc97 (diff)
implement reverse cycle through completions
Diffstat (limited to 'src')
-rw-r--r--src/app.rs5
-rw-r--r--src/command.rs6
2 files changed, 7 insertions, 4 deletions
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> {
1042 Keycode::Up => self.command_box.hist_prev(), 1042 Keycode::Up => self.command_box.hist_prev(),
1043 Keycode::Down => self.command_box.hist_next(), 1043 Keycode::Down => self.command_box.hist_next(),
1044 Keycode::Return => self.eval_command(), 1044 Keycode::Return => self.eval_command(),
1045 Keycode::Tab => self.command_box.complete_next(&self.lisp_env), 1045 Keycode::Tab if keymod == Mod::LSHIFTMOD => {
1046 self.command_box.complete(&self.lisp_env, true)
1047 }
1048 Keycode::Tab => self.command_box.complete(&self.lisp_env, false),
1046 Keycode::Escape => { 1049 Keycode::Escape => {
1047 self.command_box.clear(); 1050 self.command_box.clear();
1048 self.message.text.clear(); 1051 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 {
224 self.invalidate_completions(); 224 self.invalidate_completions();
225 } 225 }
226 226
227 pub fn complete_next(&mut self, env_list: &[Environment]) { 227 pub fn complete(&mut self, env_list: &[Environment], reverse: bool) {
228 let c = self.cursor; 228 let c = self.cursor;
229 // completions exist, fill with next completion 229 // completions exist, fill with next completion
230 if let Some(cs) = &mut self.completions { 230 if let Some(cs) = &mut self.completions {
231 self.cursor = cs.trigger_idx; 231 self.cursor = cs.trigger_idx;
232 let prev_len = cs.get().len(); 232 let prev_len = cs.get().len();
233 // skips over the first empty completion 233 // skips over the first empty completion
234 let new_insertion = cs.next(); 234 let new_insertion = if reverse { cs.prev() } else { cs.next() };
235 self.text = format!( 235 self.text = format!(
236 "{}{}{}", 236 "{}{}{}",
237 &self.text[..self.cursor], 237 &self.text[..self.cursor],
@@ -249,7 +249,7 @@ impl CommandBox {
249 .map(|&s| s.to_owned()) 249 .map(|&s| s.to_owned())
250 .collect(), 250 .collect(),
251 )); 251 ));
252 self.complete_next(env_list) 252 self.complete(env_list, reverse)
253 } 253 }
254 } 254 }
255} 255}