diff options
author | Akshay <[email protected]> | 2021-05-17 12:28:19 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-05-17 12:28:19 +0100 |
commit | bea80dbfe722c7bb13e19665ddbadea03b8b6293 (patch) | |
tree | c7685af23965cfaeb19969291d1d883bffc83039 /src/command.rs | |
parent | d2cc31ee49d673f343ce5089071ef3628c3cdc97 (diff) |
implement reverse cycle through completions
Diffstat (limited to 'src/command.rs')
-rw-r--r-- | src/command.rs | 6 |
1 files changed, 3 insertions, 3 deletions
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 | } |