@@ -28,6 +28,11 @@ pub enum PromptEvent {
2828 Abort,
2929}
3030
31+pub enum CompletionDirection {
32+ Forward,
33+ Backward,
34+}
35+
3136impl Prompt {
3237 pub fn new(
3338 prompt: String,
@@ -80,11 +85,20 @@ impl Prompt {
8085 self.exit_selection();
8186 }
8287
83− pub fn change_completion_selection(&mut self) {
88+ pub fn change_completion_selection(&mut self, direction: CompletionDirection) {
8489 if self.completion.is_empty() {
8590 return;
8691 }
87− let index = self.selection.map_or(0, |i| i + 1) % self.completion.len();
92+
93+ let index = match direction {
94+ CompletionDirection::Forward => {
95+ self.selection.map_or(0, |i| i + 1) % self.completion.len()
96+ }
97+ CompletionDirection::Backward => {
98+ (self.selection.unwrap_or(0) + self.completion.len() - 1) % self.completion.len()
99+ }
100+ };
101+
88102 self.selection = Some(index);
89103
90104 let (range, item) = &self.completion[index];
@@ -92,8 +106,8 @@ impl Prompt {
92106 self.line.replace_range(range.clone(), item);
93107
94108 self.move_end();
95− // TODO: recalculate completion when completion item is accepted, (Enter)
96109 }
110+
97111 pub fn exit_selection(&mut self) {
98112 self.selection = None;
99113 }
@@ -263,7 +277,11 @@ impl Component for Prompt {
263277 }
264278 KeyEvent {
265279 code: KeyCode::Tab, ..
266− } => self.change_completion_selection(),
280+ } => self.change_completion_selection(CompletionDirection::Forward),
281+ KeyEvent {
282+ code: KeyCode::BackTab,
283+ ..
284+ } => self.change_completion_selection(CompletionDirection::Backward),
267285 KeyEvent {
268286 code: KeyCode::Char('q'),
269287 modifiers: KeyModifiers::CONTROL,