diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-25 16:59:39 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-25 16:59:39 -0400 |
commit | 27d3b33f44b68582d500f787e8f2fe5b68a4867d (patch) | |
tree | d4feb379ef551009c57c8bf011478e5bd679c6d7 | |
parent | 62a3f87502373c25d0cfd9ce35b966b4f199673e (diff) |
tab autocomplete supports partial inputs
- rather than replacing the entire input stream with the autocomplete candidate,
it only replaces from the last whitespace; rustyline's default behaviour
-rw-r--r-- | src/preview.rs | 62 | ||||
-rw-r--r-- | src/textfield.rs | 6 |
2 files changed, 33 insertions, 35 deletions
diff --git a/src/preview.rs b/src/preview.rs index 3aaf9ce..44bcd41 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -61,39 +61,37 @@ fn preview_file(entry: &JoshutoDirEntry, win: &JoshutoPanel) { match path.extension() { Some(file_ext) => match PREVIEW_T.extension.get(file_ext.to_str().unwrap()) { Some(s) => preview_with(path, win, &s), - None => {} - /* - None => if let Some(mimetype) = tree_magic::from_filepath(&path) { - match PREVIEW_T.mimetype.get(mimetype.as_str()) { - Some(s) => preview_with(path, win, &s), - None => if let Some(ind) = mimetype.find('/') { - let supertype = &mimetype[..ind]; - if supertype == "text" { - preview_text(path, win); - } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) { - preview_with(path, win, &s); - } - }, - } - } - */ + None => {} /* + None => if let Some(mimetype) = tree_magic::from_filepath(&path) { + match PREVIEW_T.mimetype.get(mimetype.as_str()) { + Some(s) => preview_with(path, win, &s), + None => if let Some(ind) = mimetype.find('/') { + let supertype = &mimetype[..ind]; + if supertype == "text" { + preview_text(path, win); + } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) { + preview_with(path, win, &s); + } + }, + } + } + */ }, - None => {} - /* - if let Some(mimetype) = tree_magic::from_filepath(&path) { - match PREVIEW_T.mimetype.get(mimetype.as_str()) { - Some(s) => preview_with(path, win, &s), - None => if let Some(ind) = mimetype.find('/') { - let supertype = &mimetype[..ind]; - if supertype == "text" { - preview_text(path, win); - } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) { - preview_with(path, win, &s); - } - }, - } - } - */ + None => {} /* + if let Some(mimetype) = tree_magic::from_filepath(&path) { + match PREVIEW_T.mimetype.get(mimetype.as_str()) { + Some(s) => preview_with(path, win, &s), + None => if let Some(ind) = mimetype.find('/') { + let supertype = &mimetype[..ind]; + if supertype == "text" { + preview_text(path, win); + } else if let Some(s) = PREVIEW_T.mimetype.get(supertype) { + preview_with(path, win, &s); + } + }, + } + } + */ } } diff --git a/src/textfield.rs b/src/textfield.rs index e1ddd06..fb4c9bc 100644 --- a/src/textfield.rs +++ b/src/textfield.rs @@ -113,8 +113,8 @@ impl JoshutoTextField { completion_tracker.take(); } } else if ch == keymap::TAB { - if completion_tracker.is_none() && line_buffer.len() == line_buffer.pos() { - let res = completer.complete_path(line_buffer.as_str(), line_buffer.len()); + if completion_tracker.is_none() { + let res = completer.complete_path(line_buffer.as_str(), line_buffer.pos()); if let Ok((pos, mut candidates)) = res { candidates.sort_by(|x, y| { x.display() @@ -133,7 +133,7 @@ impl JoshutoTextField { if let Some(ref mut s) = completion_tracker { if s.index < s.candidates.len() { let candidate = &s.candidates[s.index]; - completer.update(&mut line_buffer, 0, candidate.display()); + completer.update(&mut line_buffer, s.pos, candidate.display()); s.index += 1; } } |