Improve e handling
This commit is contained in:
parent
c1d54f8b5e
commit
d18b995228
17
src/main.rs
17
src/main.rs
@ -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,12 +341,19 @@ 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>() {
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Key::Right => {
|
||||
calc_operation(app, '>');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user