@@ -53,7 +53,16 @@ impl Prompt {
55 pub fn insert_char(&mut self, c: char) {
55 pub fn insert_char(&mut self, c: char) {
56+ let pos = if self.line.is_empty() {
63+ .unwrap_or_else(|| self.line.len())
56− self.line.insert(self.cursor, c);
65+ self.line.insert(pos, c);
57 self.cursor += 1;
66 self.cursor += 1;
58 self.completion = (self.completion_fn)(&self.line);
67 self.completion = (self.completion_fn)(&self.line);
59 self.exit_selection();
68 self.exit_selection();
@@ -79,7 +88,13 @@ impl Prompt {
80 pub fn delete_char_backwards(&mut self) {
89 pub fn delete_char_backwards(&mut self) {
81 if self.cursor > 0 {
90 if self.cursor > 0 {
82− self.line.remove(self.cursor - 1);
94+ .nth(self.cursor - 1)
96+ .expect("line is not empty");
97+ self.line.remove(pos);
83 self.cursor -= 1;
98 self.cursor -= 1;
84 self.completion = (self.completion_fn)(&self.line);
99 self.completion = (self.completion_fn)(&self.line);