ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #02865
[Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-keyboard-swipe-fix into lp:ubuntu-calculator-app
Bartosz Kosiorek has proposed merging lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-keyboard-swipe-fix into lp:ubuntu-calculator-app.
Commit message:
Fix for keyboard swiping
Requested reviews:
Ubuntu Calculator Developers (ubuntu-calculator-dev)
Related bugs:
Bug #1442973 in Ubuntu Calculator App: "[reboot] Keyboard does not move back"
https://bugs.launchpad.net/ubuntu-calculator-app/+bug/1442973
For more details, see:
https://code.launchpad.net/~gang65/ubuntu-calculator-app/ubuntu-calculator-app-keyboard-swipe-fix/+merge/262275
Fix for keyboard swiping
--
Your team Ubuntu Calculator Developers is requested to review the proposed merge of lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-keyboard-swipe-fix into lp:ubuntu-calculator-app.
=== modified file 'app/engine/formula.js'
--- app/engine/formula.js 2015-03-26 21:16:14 +0000
+++ app/engine/formula.js 2015-06-17 21:30:32 +0000
@@ -90,14 +90,21 @@
return couldAddOperator(formula, stringToAddToFormula[0]);
}
- if (stringToAddToFormula === ".") {
+ // After decimal separator only number is allowed
+ if (isNaN(stringToAddToFormula)) {
+ if (formula.slice(-1) === ".") {
+ return false;
+ }
+ }
+
+ if (stringToAddToFormula.slice(-1) === ".") {
return couldAddDot(formula);
}
if (stringToAddToFormula === ")") {
return couldAddCloseBracket(formula);
}
-
+
// Validate complex numbers
if ((stringToAddToFormula === "i") || (!isNaN(stringToAddToFormula))){
if (formula.slice(-1) === "i") {
@@ -226,11 +233,6 @@
* @return bool: true if the dot could be added, false otherwhise
*/
function couldAddDot(formulaToCheck) {
- // A dot could be only after a number
- if ((isNaN(formulaToCheck.slice(-1))) || (formulaToCheck === "")) {
- return false;
- }
-
// If is after a number and it's the first dot of the calc it could be added
if (formulaToCheck.indexOf('.') === -1) {
return true;
=== modified file 'app/ubuntu-calculator-app.qml'
--- app/ubuntu-calculator-app.qml 2015-06-11 15:40:14 +0000
+++ app/ubuntu-calculator-app.qml 2015-06-17 21:30:32 +0000
@@ -137,6 +137,10 @@
if (!isNaN(visual) && isLastCalculate) {
longFormula = displayedInputText = shortFormula = "";
}
+ // Add zero when decimal separator is not after number
+ if ((visual === ".") && ((isNaN(longFormula.slice(textInputField.cursorPosition - 1, textInputField.cursorPosition))) || (longFormula === ""))) {
+ visual = "0.";
+ }
isLastCalculate = false;
if (visual === "()") {
=== modified file 'app/ui/CalcKeyboard.qml'
--- app/ui/CalcKeyboard.qml 2015-03-05 22:57:16 +0000
+++ app/ui/CalcKeyboard.qml 2015-06-17 21:30:32 +0000
@@ -22,8 +22,8 @@
id: virtualKeyboard
height: flickableKeyboard.height + units.gu(1)
- property int pressedKey: -1
- property string pressedKeyText: ""
+ property int pressedKey: -1;
+ property string pressedKeyText: "";
default property alias children: keyboardsRow.children
@@ -38,21 +38,23 @@
property int currentIndex: 0
- onDragEnded: {
+ onMovementEnded: {
var index = 0;
if (horizontalVelocity > units.gu(50)) {
- index = Math.min(keyboardsRow.children.length - 1, currentIndex + 1)
+ // Don't allow to change index above the number of keyboards
+ index = Math.min(keyboardsRow.children.length - 1, currentIndex + 1);
} else if (horizontalVelocity < -units.gu(50)) {
- index = Math.max(0, currentIndex - 1)
+ // Don't allow to change index below 0
+ index = Math.max(0, currentIndex - 1);
} else {
- index = Math.round(contentX / (width + keyboardsRow.spacing))
- index = Math.max(0, index)
- index = Math.min(keyboardsRow.children.length - 1, index)
+ index = Math.round(contentX / (width + keyboardsRow.spacing));
+ index = Math.max(0, index);
+ index = Math.min(keyboardsRow.children.length - 1, index);
}
currentIndex = index;
- snapAnimation.to = index * (flickableKeyboard.width)
- snapAnimation.start()
+ snapAnimation.to = index * (flickableKeyboard.width);
+ snapAnimation.start();
}
UbuntuNumberAnimation {
=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
--- tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-26 22:41:49 +0000
+++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-06-17 21:30:32 +0000
@@ -192,6 +192,16 @@
self.app.main_view.insert('-1=')
self._assert_result_is(u'0.666666666667')
+ def test_comma_without_number_validation(self):
+ # Validation of the decimal separator
+ # We are trying to add several commas into one number
+ # Only first comma in the number should be allowed
+ self.app.main_view.insert('..1.3*.*5.=')
+ self._assert_result_is(u'0.065')
+ self._assert_history_contains(u'0.13×0.5=0.065')
+ self.app.main_view.insert('.7')
+ self._assert_result_is(u'0.0657')
+
def test_square(self):
self.app.main_view.insert('4')
self.app.main_view.show_scientific_keyboard()
Follow ups