Skip to content

Commit

Permalink
change flag name: offset -> is_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoto7250 committed Apr 15, 2022
1 parent 6f38dc9 commit 4a52500
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/components/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ALL_RESERVED_WORDS: &[&str] = &[
pub struct CompletionComponent {
key_config: KeyConfig,
state: ListState,
offset: bool,
is_empty: bool,
word: String,
candidates: Vec<String>,
}
Expand All @@ -38,14 +38,14 @@ impl CompletionComponent {
.map(|w| w.to_string())
.collect()
},
offset: false,
is_empty: true,
}
}

pub fn update(&mut self, word: impl Into<String>) {
self.word = word.into();
self.state.select(Some(0));
self.offset = false;
self.is_empty = true;
}

fn next(&mut self) {
Expand Down Expand Up @@ -112,8 +112,10 @@ impl MovableComponent for CompletionComponent {
.map(|c| ListItem::new(c.to_string()))
.collect::<Vec<ListItem>>();
if candidates.clone().is_empty() {
self.offset = false;
self.is_empty = true;
return Ok(());
} else {
self.is_empty = false;
}
let candidate_list = List::new(candidates.clone())
.block(Block::default().borders(Borders::ALL))
Expand All @@ -130,7 +132,6 @@ impl MovableComponent for CompletionComponent {
.min(f.size().bottom().saturating_sub(area.y + y + 2)),
);

self.offset = true;
f.render_widget(Clear, area);
f.render_stateful_widget(candidate_list, area, &mut self.state);
}
Expand All @@ -142,10 +143,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 && self.offset {
if key == self.key_config.move_down && !self.is_empty {
self.next();
return Ok(EventState::Consumed);
} else if key == self.key_config.move_up && self.offset {
} else if key == self.key_config.move_up && !self.is_empty {
self.previous();
return Ok(EventState::Consumed);
}
Expand Down

0 comments on commit 4a52500

Please sign in to comment.