Improve e handling

This commit is contained in:
Austen Adler 2021-04-26 18:11:23 -04:00
parent c1d54f8b5e
commit d18b995228

View File

@ -326,6 +326,14 @@ fn handle_key(app: &mut App, events: &Events, key: Key) {
app.input.push(c);
}
Key::Char(c @ 'e') | Key::Char(c @ '.') => {
if app.input.is_empty() {
if let Ok(x) = app.calculator.pop() {
app.input = x.to_string();
} else {
return;
}
}
if !app.input.contains(c) {
app.input.push(c);
}
@ -333,9 +341,16 @@ fn handle_key(app: &mut App, events: &Events, key: Key) {
Key::Char('\n') | Key::Char(' ') => {
if app.input.is_empty() {
calc_operation(app, '\n');
} else if let Ok(f) = app.input.parse::<f64>() {
if app.calculator.push(f).is_ok() {
app.input.clear();
} else {
let mut tmp_input = app.input.clone();
if tmp_input.ends_with('e') {
let tmp_input = tmp_input.push('0');
}
if let Ok(f) = tmp_input.parse::<f64>() {
if app.calculator.push(f).is_ok() {
app.input.clear();
}
}
}
}