on master help sign in
added col_height calculation
commit1a3c647adf1f252478bf38537bde87f7e5f14ab0 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateFri 13 Nov 2020, 00:07 (6 years ago) parent2b44031
2 files changed+15−26
helix-term/src/application.rs+9−9 helix-view/src/prompt.rs+6−17
helix-term/src/application.rs+9−9
@@ -241,7 +241,12 @@ impl Renderer {
241241 // completion
242242 if !prompt.completion.is_empty() {
243243 // TODO: find out better way of clearing individual lines of the screen
244− for i in (3..7) {
244+ let mut row = 0;
245+ let mut col = 0;
246+ let max_col = self.size.0 / BASE_WIDTH;
247+ let col_height = ((prompt.completion.len() as u16 + max_col - 1) / max_col);
248+
249+ for i in (3..col_height + 3) {
245250 self.surface.set_string(
246251 0,
247252 self.size.1 - i as u16,
@@ -250,14 +255,9 @@ impl Renderer {
250255 );
251256 }
252257 self.surface.set_style(
253− Rect::new(0, self.size.1 - 6, self.size.0, 4),
258+ Rect::new(0, self.size.1 - col_height - 2, self.size.0, col_height),
254259 view.theme.get("ui.statusline"),
255260 );
256− let mut row = 0;
257− let mut col = 0;
258− let max_col: u16 = self.size.0 / BASE_WIDTH;
259− // TODO: this will crash if there are too many cols added
260− // TODO: set char limit
261261 for (i, command) in prompt.completion.iter().enumerate() {
262262 let color = if prompt.completion_selection_index.is_some()
263263 && i == prompt.completion_selection_index.unwrap()
@@ -268,13 +268,13 @@ impl Renderer {
268268 };
269269 self.surface.set_stringn(
270270 1 + col * BASE_WIDTH,
271− self.size.1 - 6 + row as u16,
271+ self.size.1 - col_height - 2 + row,
272272 &command,
273273 BASE_WIDTH as usize - 1,
274274 color,
275275 );
276276 row += 1;
277− if row > 3 {
277+ if row > col_height - 1 {
278278 row = 0;
279279 col += 1;
280280 }
helix-view/src/prompt.rs+6−17
@@ -68,25 +68,14 @@ impl Prompt {
6868 }
6969
7070 pub fn change_completion_selection(&mut self) {
71− if !self.completion.is_empty() {
72− self.completion_selection_index = self
73− .completion_selection_index
74− .map(|i| {
75− if i == self.completion.len() - 1 {
76− 0
77− } else {
78− i + 1
79− }
80− })
81− .or(Some(0));
82− self.line = String::from(
83− self.completion
84− .get(self.completion_selection_index.unwrap())
85− .unwrap(),
86− );
71+ if self.completion.is_empty() {
72+ return;
8773 }
74+ let index =
75+ self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len();
76+ self.completion_selection_index = Some(index);
77+ self.line = self.completion[index].clone();
8878 }
89−
9079 pub fn exit_selection(&mut self) {
9180 self.completion_selection_index = None;
9281 }