Skip to content

Commit

Permalink
fix(tui): delete char in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot00 committed Dec 17, 2021
1 parent f61e99f commit d3996eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion quake_tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ impl App {
self.state.mode = Mode::Normal;
}
KeyCode::Char(c) => {
self.main_widget.collect_input(c);
self.main_widget.input_push(c);
}
KeyCode::Backspace => {
self.main_widget.input_pop();
}
_ => {}
},
Expand Down
8 changes: 7 additions & 1 deletion quake_tui/src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ impl MainWidget {
}
}

pub fn collect_input(&mut self, c: char) {
pub fn input_push(&mut self, c: char) {
if let Self::Editor(_, ref mut string) = self {
string.push(c);
}
}

pub fn input_pop(&mut self) {
if let Self::Editor(_, ref mut string) = self {
string.pop();
}
}
}

#[derive(Default, Clone)]
Expand Down

0 comments on commit d3996eb

Please sign in to comment.