-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completion suggestion #4
Conversation
helix-term/src/application.rs
Outdated
); | ||
let mut row = 0; | ||
let mut col = 0; | ||
let max_row: u16 = self.size.0 / BASE_WIDTH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
row -> col, col -> row. https://en.wikipedia.org/wiki/Column_(typography)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be calculating max amount of columns possible on the screen. A 150 char screen can fit 150 / 30 => 5 columns onto one row.
helix-term/src/application.rs
Outdated
color, | ||
); | ||
col += 1; | ||
if col > 3 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be rendering up to max_col.
self.terminal.render_prompt(prompt); | ||
if let Some(prompt) = &self.prompt { | ||
if prompt.should_close { | ||
self.prompt = None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably not be in render but we'll fix it once there's a proper compositor.
String::from("ccc"), | ||
String::from("ddd"), | ||
String::from("eee"), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let matches = command_list.into_iter().filter(|command| command.contains(input)).collect();
if matches.is_empty() {
return None;
}
Some(matches)
@@ -307,21 +307,6 @@ pub fn append_mode(view: &mut View, _count: usize) { | |||
}) | |||
} | |||
|
|||
pub fn command_mode(_view: &mut View, _count: usize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave this here as an empty method unimplemented!()
because the prompt should be called from inside the command, we just can't do that yet without the compositor.
helix-view/src/keymap.rs
Outdated
@@ -163,7 +163,6 @@ pub fn default() -> Keymaps { | |||
vec![key!('p')] => commands::paste, | |||
vec![key!('>')] => commands::indent, | |||
vec![key!('<')] => commands::unindent, | |||
vec![key!(':')] => commands::command_mode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto here
helix-view/src/prompt.rs
Outdated
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | ||
use std::string::String; | ||
|
||
pub struct Prompt { | ||
pub prompt: String, | ||
pub line: String, | ||
pub cursor: usize, | ||
completion_fn: Box<dyn FnMut(&str) -> Option<Vec<&str>>>, | ||
pub completion: Option<Vec<String>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think about it, why not just have this as a Vec<String>
? There is no difference between None
and an empty vec from the code side.
callback_fn: impl FnMut(&mut Editor, &str) + 'static, | ||
) -> Prompt { | ||
Prompt { | ||
prompt, | ||
line: String::new(), | ||
cursor: 0, | ||
completion: completion_fn(""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can use completion_fn("").unwrap_or_default()
. If completion_fn returns Some(vec)
it'll use the vec
, if None
it'll use Vec::new
.
helix-view/src/prompt.rs
Outdated
} | ||
|
||
pub fn change_completion_selection(&mut self) { | ||
if self.completion.is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.completion.is_empty() {
return
}
..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still thinking how to simplify this further
helix-view/src/prompt.rs
Outdated
|
||
pub fn change_completion_selection(&mut self) { | ||
if !self.completion.is_empty() { | ||
self.completion_selection_index = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn change_completion_selection(&mut self) {
if self.completion.is_empty() {
return
}
let index = self.completion_selection_index.map(|i| i + 1).unwrap_or(0) % self.completion.len();
self.completion_selection_index = Some(index);
self.line = self.completion[index].clone();
}
No description provided.