aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-10 17:17:44 +0100
committerJonas Maier <>2026-03-10 17:17:44 +0100
commit725acee81e4c2a90264dbe45f860a5723c1a6fa5 (patch)
treec88723b7b90875f6976978ccf50878dd3370f325 /src
parentf4867b2164201c8edcb4c59b41107c1cd880a513 (diff)
downloadpish-725acee81e4c2a90264dbe45f860a5723c1a6fa5.tar.gz
automatically applies longest shared prefix of suggestions
Diffstat (limited to 'src')
-rw-r--r--src/main.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 2be6562..1dbd024 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -371,8 +371,9 @@ fn event_loop() {
}
parse::CompletionKind::None => continue,
};
-
+
suggestions.sort_by(|x, y| x.delta.cmp(&y.delta));
+ suggestions.dedup_by(|x, y| x.delta == y.delta);
if suggestions.len() == 0 {
continue;
@@ -386,6 +387,26 @@ fn event_loop() {
continue;
}
+ // find longest shared prefix and type it
+ {
+ let mut longest = &suggestions[0].delta[..];
+ for s in suggestions.iter() {
+ let mut new = longest;
+ for i in 0..longest.len().min(s.delta.len()) {
+ if longest[i] != s.delta[i] {
+ break;
+ } else {
+ new = &s.delta[..=i];
+ }
+ }
+ longest = new;
+ }
+
+ if !longest.is_empty() {
+ se.type_bytes(longest);
+ }
+ }
+
cursor::save();
// one line below