pull/145/merge
kyoto7250 1 year ago committed by GitHub
commit 821bc7fceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ const ALL_RESERVED_WORDS: &[&str] = &[
pub struct CompletionComponent {
key_config: KeyConfig,
state: ListState,
is_empty: bool,
word: String,
candidates: Vec<String>,
}
@ -37,13 +38,14 @@ impl CompletionComponent {
.map(|w| w.to_string())
.collect()
},
is_empty: true,
}
}
pub fn update(&mut self, word: impl Into<String>) {
self.word = word.into();
self.state.select(None);
self.state.select(Some(0))
self.state.select(Some(0));
self.is_empty = true;
}
fn next(&mut self) {
@ -110,7 +112,10 @@ impl MovableComponent for CompletionComponent {
.map(|c| ListItem::new(c.to_string()))
.collect::<Vec<ListItem>>();
if candidates.clone().is_empty() {
self.is_empty = true;
return Ok(());
} else {
self.is_empty = false;
}
let candidate_list = List::new(candidates.clone())
.block(Block::default().borders(Borders::ALL))
@ -137,10 +142,10 @@ impl Component for CompletionComponent {
fn commands(&self, _out: &mut Vec<CommandInfo>) {}
fn event(&mut self, key: Key) -> Result<EventState> {
if key == self.key_config.move_down {
if key == self.key_config.move_down && !self.is_empty {
self.next();
return Ok(EventState::Consumed);
} else if key == self.key_config.move_up {
} else if key == self.key_config.move_up && !self.is_empty {
self.previous();
return Ok(EventState::Consumed);
}

Loading…
Cancel
Save