summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-21 05:13:49 +0000
committerBlaž Hrastnik2021-03-21 05:13:49 +0000
commita32806b4901dfbb85fdc6c043515033afcbdb9a7 (patch)
tree0888cb1be221964a5ac0486953fc9f35d53e4c7a /helix-term/src/commands.rs
parentf29f01858d1b8c9e54b3293879796a4650823f60 (diff)
Improve completion: src/<tab> will now correctly complete to src/main.rs
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index f84bb16e..54fea453 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -723,20 +723,26 @@ pub fn command_mode(cx: &mut Context) {
// simple heuristic: if there's no space, complete command.
// if there's a space, file completion kicks in. We should specialize by command later.
if parts.len() <= 1 {
+ use std::{borrow::Cow, ops::Range};
+ let end = 0..;
COMMAND_LIST
.iter()
.filter(|command| command.contains(input))
- .map(|command| std::borrow::Cow::Borrowed(*command))
+ .map(|command| (end.clone(), Cow::Borrowed(*command)))
.collect()
} else {
let part = parts.last().unwrap();
ui::completers::filename(part)
+ .into_iter()
+ .map(|(range, file)| {
+ // offset ranges to input
+ let offset = input.len() - part.len();
+ let range = (range.start + offset)..;
+ (range, file)
+ })
+ .collect()
// TODO
- // completion needs to be more advanced: need to return starting index for replace
- // for example, "src/" completion application.rs needs to insert after /, but "hx"
- // completion helix-core needs to replace the text.
- //
// additionally, completion items could have a info section that would get
// displayed in a popup above the prompt when items are tabbed over
}