on master help sign in
added base col width
commitc9e9fcf7c549fe98f5ac5f13cdee213da9c9ad7a authorJan Hrastnik <jan.hrastnik2@gmail.com> dateMon 2 Nov 2020, 10:41 (6 years ago) parent28a1e11
2 files changed+61−27
helix-term/src/application.rs+41−9 helix-view/src/prompt.rs+20−18
helix-term/src/application.rs+41−9
@@ -34,6 +34,8 @@ type Terminal = tui::Terminal<CrosstermBackend<std::io::Stdout>>;
3434
3535static EX: smol::Executor = smol::Executor::new();
3636
37+const BASE_WIDTH: u16 = 30;
38+
3739pub struct Application {
3840 editor: Editor,
3941 prompt: Option<Prompt>,
@@ -253,9 +255,10 @@ impl Renderer {
253255 );
254256 let mut row = 0;
255257 let mut col = 0;
258+ let max_row: u16 = self.size.0 / BASE_WIDTH;
256259 // TODO: this will crash if there are too many cols added
257260 // TODO: set char limit
258− for i in (0..completion.len()) {
261+ for (i, command) in completion.iter().enumerate() {
259262 let color = if prompt.completion_selection_index.is_some()
260263 && i == prompt.completion_selection_index.unwrap()
261264 {
@@ -263,16 +266,20 @@ impl Renderer {
263266 } else {
264267 self.text_color
265268 };
266− self.surface.set_string(
267− 1 + col * 10,
268− self.size.1 - 6 + row as u16,
269− &completion[i],
269+ self.surface.set_stringn(
270+ 1 + row * BASE_WIDTH,
271+ self.size.1 - 6 + col as u16,
272+ &command,
273+ BASE_WIDTH as usize - 1,
270274 color,
271275 );
272− row += 1;
273− if row > 3 {
274− row = 0;
275− col += 1;
276+ col += 1;
277+ if col > 3 {
278+ col = 0;
279+ row += 1;
280+ }
281+ if row > max_row {
282+ break;
276283 }
277284 }
278285 }
@@ -436,6 +443,31 @@ impl Application {
436443 String::from("ccc"),
437444 String::from("ddd"),
438445 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"),
439471 ];
440472 for command in command_list {
441473 if command.contains(_input) {
helix-view/src/prompt.rs+20−18
@@ -39,7 +39,7 @@ impl Prompt {
3939 }
4040
4141 pub fn move_char_left(&mut self) {
42− if self.cursor > 1 {
42+ if self.cursor > 0 {
4343 self.cursor -= 1;
4444 }
4545 }
@@ -68,23 +68,25 @@ impl Prompt {
6868 }
6969
7070 pub fn change_completion_selection(&mut self) {
71− self.completion_selection_index = self
72− .completion_selection_index
73− .map(|i| {
74− if i == self.completion.as_ref().unwrap().len() - 1 {
75− 0
76− } else {
77− i + 1
78− }
79− })
80− .or(Some(0));
81− self.line = String::from(
82− self.completion
83− .as_ref()
84− .unwrap()
85− .get(self.completion_selection_index.unwrap())
86− .unwrap(),
87− );
71+ if self.completion.is_some() {
72+ self.completion_selection_index = self
73+ .completion_selection_index
74+ .map(|i| {
75+ if i == self.completion.as_ref().unwrap().len() - 1 {
76+ 0
77+ } else {
78+ i + 1
79+ }
80+ })
81+ .or(Some(0));
82+ self.line = String::from(
83+ self.completion
84+ .as_ref()
85+ .unwrap()
86+ .get(self.completion_selection_index.unwrap())
87+ .unwrap(),
88+ );
89+ }
8890 }
8991
9092 pub fn exit_selection(&mut self) {