Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/05_edit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fn main() {
match *key {
KEY_LEFT => field.left(),
KEY_RIGHT => field.right(),
KEY_DC => field.delete_front(),
KEY_BACKSPACE => field.delete_back(),
_ => {
if *key as u8 as char == '\n' {
rcui.quit()
Expand Down
18 changes: 17 additions & 1 deletion src/edit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pub struct EditField {
cursor: usize,
}

// TODO(#45): EditField does not support selections
// TODO(#46): EditField does not support multiple lines (newlines)
// TODO(#47): EditField does not have a way to jump one word forward/backward
// TODO(#48): Some sort of clipboard support for EditField

impl EditField {
pub fn new() -> Self {
Self {
Expand All @@ -32,7 +37,18 @@ impl EditField {
}
}

// TODO(#39): EditField does not have a way to delete chars
pub fn delete_back(&mut self) {
if self.cursor > 0 {
self.cursor -= 1;
self.text.remove(self.cursor);
}
}

pub fn delete_front(&mut self) {
if self.cursor < self.text.len() {
self.text.remove(self.cursor);
}
}

pub fn insert_chars(&mut self, cs: &[char]) {
if self.cursor >= self.text.len() {
Expand Down