From aeeb3de55b9749d345edcc33cf7f3ef08eb97899 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 12 Sep 2021 12:26:21 +0900 Subject: [PATCH] fix variable name --- src/components/completion.rs | 15 ++++++++------- src/components/table_filter.rs | 13 ++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/completion.rs b/src/components/completion.rs index b0d7cea..7d825f9 100644 --- a/src/components/completion.rs +++ b/src/components/completion.rs @@ -11,7 +11,9 @@ use tui::{ Frame, }; -const RESERVED_WORDS: &[&str] = &["IN", "AND", "OR", "NOT", "NULL", "IS"]; +const RESERVED_WORDS: &[&str] = &[ + "IN", "AND", "OR", "NOT", "NULL", "IS", +]; pub struct CompletionComponent { key_config: KeyConfig, @@ -95,15 +97,14 @@ impl MovableComponent for CompletionComponent { ) -> Result<()> { if !self.word.is_empty() { let width = 30; - let height = 5; let candidates = self .filterd_candidates() - .map(|c| ListItem::new(c.to_string()).style(Style::default())) + .map(|c| ListItem::new(c.to_string())) .collect::>(); - if candidates.is_empty() { + if candidates.clone().is_empty() { return Ok(()); } - let candidates = List::new(candidates) + let candidate_list = List::new(candidates.clone()) .block(Block::default().borders(Borders::ALL)) .highlight_style(Style::default().bg(Color::Blue)) .style(Style::default()); @@ -112,10 +113,10 @@ impl MovableComponent for CompletionComponent { area.x + x, area.y + y + 2, width.min(f.size().width), - height.min(f.size().height), + candidates.len().min(5) as u16 + 2, ); f.render_widget(Clear, area); - f.render_stateful_widget(candidates, area, &mut self.state); + f.render_stateful_widget(candidate_list, area, &mut self.state); } Ok(()) } diff --git a/src/components/table_filter.rs b/src/components/table_filter.rs index 8b357ff..8856555 100644 --- a/src/components/table_filter.rs +++ b/src/components/table_filter.rs @@ -163,10 +163,11 @@ impl DrawableComponent for TableFilterComponent { (self .table .as_ref() - .map_or(String::new(), |table| table.name.to_string()) - .width() as u16 - + 2) - .saturating_add(self.input_cursor_position), + .map_or(String::new(), |table| { + format!("{} ", table.name.to_string()) + }) + .width() as u16) + .saturating_add(self.input_cursor_position), 0, )?; }; @@ -196,7 +197,9 @@ impl Component for TableFilterComponent { // apply comletion candidates if key == self.key_config.enter { - self.complete()?; + if self.complete()?.is_consumed() { + return Ok(EventState::Consumed); + }; } self.completion.selected_candidate();