@@ 31,13 31,29 @@ impl InputBuffer {
}
pub fn insert(&mut self, ch: char) {
- self.buffer.push(ch);
- self.advance();
+ if self.pos < self.buffer.len() {
+ self.buffer.insert(self.pos, ch);
+ } else {
+ self.buffer.push(ch);
+ }
+
+ self.cursor_right();
}
pub fn backspace(&mut self) {
- self.buffer.pop();
- self.retreat();
+ if self.pos < self.buffer.len() {
+ self.buffer.remove(self.pos - 1);
+ } else {
+ self.buffer.pop();
+ }
+
+ self.cursor_left();
+ }
+
+ pub fn delete(&mut self) {
+ if self.pos < self.buffer.len() {
+ self.buffer.remove(self.pos);
+ }
}
pub fn cursor_left(&mut self) {
@@ 62,27 78,6 @@ impl InputBuffer {
}
}
- fn advance(&mut self) {
- self.pos += 1;
-
- if self.pos > self.end {
- // move viewport forwards
- self.start += 1;
- self.end += 1;
- }
- }
-
- fn retreat(&mut self) {
- if self.pos <= 0 { return; } // ... no.
-
- self.pos -= 1;
-
- if self.start > 0 {
- self.start -= 1;
- self.end -= 1;
- }
- }
-
fn span_len(&self) -> usize {
self.end - self.start
}
@@ 248,6 243,10 @@ impl Shell {
self.buffer.backspace();
},
+ event::KeyCode::Delete => {
+ self.buffer.delete();
+ },
+
event::KeyCode::Left => {
self.buffer.cursor_left();
},