Skip to content
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

Merged
merged 10 commits into from
Dec 2, 2020
Merged

Completion suggestion #4

merged 10 commits into from
Dec 2, 2020

Conversation

janhrastnik
Copy link
Contributor

No description provided.

);
let mut row = 0;
let mut col = 0;
let max_row: u16 = self.size.0 / BASE_WIDTH;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

color,
);
col += 1;
if col > 3 {
Copy link
Member

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;
Copy link
Member

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"),
];
Copy link
Member

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) {
Copy link
Member

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.

@@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here

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>>,
Copy link
Member

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(""),
Copy link
Member

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.

}

pub fn change_completion_selection(&mut self) {
if self.completion.is_some() {
Copy link
Member

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
}
..

Copy link
Member

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


pub fn change_completion_selection(&mut self) {
if !self.completion.is_empty() {
self.completion_selection_index = self
Copy link
Member

@archseer archseer Nov 3, 2020

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();
}

@archseer archseer merged commit 2e12fc9 into master Dec 2, 2020
@archseer archseer deleted the completion-suggestion branch December 2, 2020 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants