aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/prompt.rs
diff options
context:
space:
mode:
authorJan Hrastnik2021-06-19 12:51:53 +0000
committerJan Hrastnik2021-06-19 12:51:53 +0000
commitcdd9347457f0608346894cd0aab35b412cb59a7b (patch)
tree468078c37311cb1c7f9e7d4bd8a03c493d25e669 /helix-term/src/ui/prompt.rs
parent97323dc2f90f81afc82bd929d111abda540bebe5 (diff)
parent2cbec2b0470d0759578929b224c445b69617b6b6 (diff)
Merge remote-tracking branch 'origin/master' into line_ending_detection
Diffstat (limited to 'helix-term/src/ui/prompt.rs')
-rw-r--r--helix-term/src/ui/prompt.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs
index 7b8af820..991b328d 100644
--- a/helix-term/src/ui/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -53,7 +53,16 @@ impl Prompt {
}
pub fn insert_char(&mut self, c: char) {
- self.line.insert(self.cursor, c);
+ let pos = if self.line.is_empty() {
+ 0
+ } else {
+ self.line
+ .char_indices()
+ .nth(self.cursor)
+ .map(|(pos, _)| pos)
+ .unwrap_or_else(|| self.line.len())
+ };
+ self.line.insert(pos, c);
self.cursor += 1;
self.completion = (self.completion_fn)(&self.line);
self.exit_selection();
@@ -79,7 +88,13 @@ impl Prompt {
pub fn delete_char_backwards(&mut self) {
if self.cursor > 0 {
- self.line.remove(self.cursor - 1);
+ let pos = self
+ .line
+ .char_indices()
+ .nth(self.cursor - 1)
+ .map(|(pos, _)| pos)
+ .expect("line is not empty");
+ self.line.remove(pos);
self.cursor -= 1;
self.completion = (self.completion_fn)(&self.line);
}