@@ -28,6 +28,11 @@ pub enum PromptEvent {
31+pub enum CompletionDirection {
31impl Prompt {
36impl Prompt {
32 pub fn new(
37 pub fn new(
33 prompt: String,
38 prompt: String,
@@ -80,11 +85,20 @@ impl Prompt {
80 self.exit_selection();
85 self.exit_selection();
83− pub fn change_completion_selection(&mut self) {
88+ pub fn change_completion_selection(&mut self, direction: CompletionDirection) {
84 if self.completion.is_empty() {
89 if self.completion.is_empty() {
93+ let index = match direction {
94+ CompletionDirection::Forward => {
87− let index = self.selection.map_or(0, |i| i + 1) % self.completion.len();
95+ self.selection.map_or(0, |i| i + 1) % self.completion.len()
97+ CompletionDirection::Backward => {
98+ (self.selection.unwrap_or(0) + self.completion.len() - 1) % self.completion.len()
88 self.selection = Some(index);
102 self.selection = Some(index);
90 let (range, item) = &self.completion[index];
104 let (range, item) = &self.completion[index];
@@ -92,8 +106,8 @@ impl Prompt {
92 self.line.replace_range(range.clone(), item);
106 self.line.replace_range(range.clone(), item);
94 self.move_end();
108 self.move_end();
95− // TODO: recalculate completion when completion item is accepted, (Enter)
97 pub fn exit_selection(&mut self) {
111 pub fn exit_selection(&mut self) {
98 self.selection = None;
112 self.selection = None;
@@ -263,7 +277,11 @@ impl Component for Prompt {
264 KeyEvent {
278 KeyEvent {
265 code: KeyCode::Tab, ..
279 code: KeyCode::Tab, ..
266− } => self.change_completion_selection(),
280+ } => self.change_completion_selection(CompletionDirection::Forward),
282+ code: KeyCode::BackTab,
284+ } => self.change_completion_selection(CompletionDirection::Backward),
267 KeyEvent {
285 KeyEvent {
268 code: KeyCode::Char('q'),
286 code: KeyCode::Char('q'),
269 modifiers: KeyModifiers::CONTROL,
287 modifiers: KeyModifiers::CONTROL,