on master help sign in
added base col width
c9e9fcfJan Hrastnik
helix-term/src/application.rs+41−9
@@ -34,6 +34,8 @@ type Terminal = tui::Terminal<CrosstermBackend<std::io::Stdout>>;
34
34
35static EX: smol::Executor = smol::Executor::new();
35static EX: smol::Executor = smol::Executor::new();
36
36
37+const BASE_WIDTH: u16 = 30;
38+
37pub struct Application {
39pub struct Application {
38 editor: Editor,
40 editor: Editor,
39 prompt: Option<Prompt>,
41 prompt: Option<Prompt>,
@@ -253,9 +255,10 @@ impl Renderer {
253 );
255 );
254 let mut row = 0;
256 let mut row = 0;
255 let mut col = 0;
257 let mut col = 0;
258+ let max_row: u16 = self.size.0 / BASE_WIDTH;
256 // TODO: this will crash if there are too many cols added
259 // TODO: this will crash if there are too many cols added
257 // TODO: set char limit
260 // TODO: set char limit
258− for i in (0..completion.len()) {
261+ for (i, command) in completion.iter().enumerate() {
259 let color = if prompt.completion_selection_index.is_some()
262 let color = if prompt.completion_selection_index.is_some()
260 && i == prompt.completion_selection_index.unwrap()
263 && i == prompt.completion_selection_index.unwrap()
261 {
264 {
@@ -263,16 +266,20 @@ impl Renderer {
263 } else {
266 } else {
264 self.text_color
267 self.text_color
265 };
268 };
266− self.surface.set_string(
269+ self.surface.set_stringn(
267− 1 + col * 10,
270+ 1 + row * BASE_WIDTH,
268− self.size.1 - 6 + row as u16,
271+ self.size.1 - 6 + col as u16,
269− &completion[i],
272+ &command,
273+ BASE_WIDTH as usize - 1,
270 color,
274 color,
271 );
275 );
272− row += 1;
276+ col += 1;
273− if row > 3 {
277+ if col > 3 {
274− row = 0;
278+ col = 0;
275− col += 1;
279+ row += 1;
280+ }
281+ if row > max_row {
282+ break;
276 }
283 }
277 }
284 }
278 }
285 }
@@ -436,6 +443,31 @@ impl Application {
436 String::from("ccc"),
443 String::from("ccc"),
437 String::from("ddd"),
444 String::from("ddd"),
438 String::from("eee"),
445 String::from("eee"),
446+ String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"),
447+ String::from("q"),
448+ String::from("aaa"),
449+ String::from("bbb"),
450+ String::from("ccc"),
451+ String::from("ddd"),
452+ String::from("eee"),
453+ String::from("q"),
454+ String::from("aaa"),
455+ String::from("bbb"),
456+ String::from("ccc"),
457+ String::from("ddd"),
458+ String::from("eee"),
459+ String::from("q"),
460+ String::from("aaa"),
461+ String::from("bbb"),
462+ String::from("ccc"),
463+ String::from("ddd"),
464+ String::from("eee"),
465+ String::from("q"),
466+ String::from("aaa"),
467+ String::from("bbb"),
468+ String::from("ccc"),
469+ String::from("ddd"),
470+ String::from("eee"),
439 ];
471 ];
440 for command in command_list {
472 for command in command_list {
441 if command.contains(_input) {
473 if command.contains(_input) {
helix-view/src/prompt.rs+20−18
@@ -39,7 +39,7 @@ impl Prompt {
39 }
39 }
40
40
41 pub fn move_char_left(&mut self) {
41 pub fn move_char_left(&mut self) {
42− if self.cursor > 1 {
42+ if self.cursor > 0 {
43 self.cursor -= 1;
43 self.cursor -= 1;
44 }
44 }
45 }
45 }
@@ -68,23 +68,25 @@ 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_some() {
71− self.completion_selection_index = self
72+ self.completion_selection_index = self
72− .completion_selection_index
73+ .completion_selection_index
73− .map(|i| {
74+ .map(|i| {
74− if i == self.completion.as_ref().unwrap().len() - 1 {
75+ if i == self.completion.as_ref().unwrap().len() - 1 {
75− 0
76+ 0
76− } else {
77+ } else {
77− i + 1
78+ i + 1
78− }
79+ }
79− })
80+ })
80− .or(Some(0));
81+ .or(Some(0));
81− self.line = String::from(
82+ self.line = String::from(
82− self.completion
83+ self.completion
83− .as_ref()
84+ .as_ref()
84− .unwrap()
85+ .unwrap()
85− .get(self.completion_selection_index.unwrap())
86+ .get(self.completion_selection_index.unwrap())
86− .unwrap(),
87+ .unwrap(),
87− );
88+ );
89+ }
88 }
90 }
89
91
90 pub fn exit_selection(&mut self) {
92 pub fn exit_selection(&mut self) {