summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRory Dudley2024-09-30 21:55:42 -0600
committerRory Dudley2024-09-30 23:02:19 -0600
commit41335c1618d3c7c1c5950a228ea15e2d0c3c2d8d (patch)
treed3e44843b172d10ece02c90c291e35945c399360 /src
parent15245cb72d205f967e67518d7cded26ef42ec3a7 (diff)
downloaddwarvish-41335c1618d3c7c1c5950a228ea15e2d0c3c2d8d.tar.gz
Add backslashes to words with spaces in autocomplete()
This patch makes it so that the autcomplete() function automatically inserts the backslash character (`\`) into words with spaces when cylcing through the options. Signed-off-by: Rory Dudley <rory@netc.lu>
Diffstat (limited to 'src')
-rw-r--r--src/buffer.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/buffer.rs b/src/buffer.rs
index c27946f..4d00d34 100644
--- a/src/buffer.rs
+++ b/src/buffer.rs
@@ -154,12 +154,22 @@ fn autocomplete(
path.file_name().unwrap().to_str().unwrap().to_string()
};
- let path = if word.is_empty() {
+ let mut path = if word.is_empty() {
path
} else {
path[word.len()..].to_string()
};
+ let pause_positions = path
+ .chars()
+ .enumerate()
+ .filter(|(_, c)| *c == ' ')
+ .map(|(i, _)| i)
+ .collect::<Vec<_>>();
+ for pos in pause_positions {
+ path.insert(pos, '\\');
+ }
+
print!("{}", path);
Ok((path, paths.len()))