Skip to content

Commit

Permalink
Improve backspace behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
apesic committed Sep 19, 2020
1 parent 853e00f commit cdf1179
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "dev.pesic.rpncalc"
minSdkVersion 16
targetSdkVersion 30
Expand Down
9 changes: 8 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ class _AppHomeState extends State<AppHome> {
});
}

void _handleDrop() {
_setStateWithUndo(() {
HapticFeedback.lightImpact();
_stack.drop();
});
}

void _applyBinaryOperation(BinaryOperator op) {
_setStateWithUndo(() {
HapticFeedback.lightImpact();
Expand Down Expand Up @@ -298,7 +305,7 @@ class _AppHomeState extends State<AppHome> {
HapticFeedback.selectionClick();
_setStateWithUndo(_stack.backspaceCurrent);
},
onLongPress: _handleClear,
onLongPress: _handleDrop,
child: const Icon(
Icons.backspace,
semanticLabel: 'Backspace',
Expand Down
7 changes: 7 additions & 0 deletions lib/rpn_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class RpnStack {
return null;
}

void drop() {
_pop();
if (stack.isEmpty) {
push(EditableItem.blank());
}
}

void advance() {
final current = stack.first;
_realizeStack();
Expand Down

0 comments on commit cdf1179

Please sign in to comment.