on master help sign in
added col_height calculation
1a3c647Jan Hrastnik
helix-term/src/application.rs+9−9
@@ -241,7 +241,12 @@ impl Renderer {
241 // completion
241 // completion
242 if !prompt.completion.is_empty() {
242 if !prompt.completion.is_empty() {
243 // TODO: find out better way of clearing individual lines of the screen
243 // TODO: find out better way of clearing individual lines of the screen
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+
244− for i in (3..7) {
249+ for i in (3..col_height + 3) {
245 self.surface.set_string(
250 self.surface.set_string(
246 0,
251 0,
247 self.size.1 - i as u16,
252 self.size.1 - i as u16,
@@ -250,14 +255,9 @@ impl Renderer {
250 );
255 );
251 }
256 }
252 self.surface.set_style(
257 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),
254 view.theme.get("ui.statusline"),
259 view.theme.get("ui.statusline"),
255 );
260 );
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
261 for (i, command) in prompt.completion.iter().enumerate() {
261 for (i, command) in prompt.completion.iter().enumerate() {
262 let color = if prompt.completion_selection_index.is_some()
262 let color = if prompt.completion_selection_index.is_some()
263 && i == prompt.completion_selection_index.unwrap()
263 && i == prompt.completion_selection_index.unwrap()
@@ -268,13 +268,13 @@ impl Renderer {
268 };
268 };
269 self.surface.set_stringn(
269 self.surface.set_stringn(
270 1 + col * BASE_WIDTH,
270 1 + col * BASE_WIDTH,
271− self.size.1 - 6 + row as u16,
271+ self.size.1 - col_height - 2 + row,
272 &command,
272 &command,
273 BASE_WIDTH as usize - 1,
273 BASE_WIDTH as usize - 1,
274 color,
274 color,
275 );
275 );
276 row += 1;
276 row += 1;
277− if row > 3 {
277+ if row > col_height - 1 {
278 row = 0;
278 row = 0;
279 col += 1;
279 col += 1;
280 }
280 }
helix-view/src/prompt.rs+6−17
@@ -68,25 +68,14 @@ impl Prompt {
68 }
68 }
69
69
70 pub fn change_completion_selection(&mut self) {
70 pub fn change_completion_selection(&mut self) {
71− if !self.completion.is_empty() {
71+ if self.completion.is_empty() {
72− self.completion_selection_index = self
72+ return;
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− );
87 }
73 }
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();
88 }
78 }
89−
90 pub fn exit_selection(&mut self) {
79 pub fn exit_selection(&mut self) {
91 self.completion_selection_index = None;
80 self.completion_selection_index = None;
92 }
81 }