~mterry/ubuntu-calculator-app/confined

« back to all changes in this revision

Viewing changes to app/ubuntu-calculator-app.qml

Allow navigating the history using the arrow keys. Fixes: https://bugs.launchpad.net/bugs/1466627.

Approved by Jenkins Bot, Bartosz Kosiorek.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
    // Var used to save favourite calcs
76
76
    property bool isFavourite: false
77
77
 
 
78
    // Var used to store calculation history position
 
79
    property var historyPosition: calculationHistory.getContents().count;
 
80
 
 
81
    // Var used to save if user is using history.
 
82
    property bool isUsingHistory: false;
 
83
 
 
84
    // Var used to store the last formula which is being written.
 
85
    property string lastWrittenFormula: "";
 
86
 
78
87
    // Var used to store currently edited calculation history item
79
88
    property int editedCalculationIndex: -1
80
89
 
311
320
 
312
321
            // Some special keys like backspace captured in TextField,
313
322
            // are for some reason not sent to the application but to the text input
314
 
            Keys.onPressed: textInputField.keyPress(event)
 
323
            Keys.onPressed: {event.accepted = true; textInputField.keyPress(event)}
315
324
            Keys.onReleased: textInputField.keyRelease(event)
316
325
 
317
326
            head.visible: false
619
628
 
620
629
                        function keyPress(event) {
621
630
                            if (!(event.modifiers & Qt.ControlModifier || event.modifiers & Qt.AltModifier)) { // Shift needs to be passed through as it may be required for some special keys
 
631
                                if((event.key === Qt.Key_Up || event.key === Qt.Key_Down) && event.accepted) {
 
632
                                    if(event.key === Qt.Key_Up && historyPosition > 1)
 
633
                                        historyPosition--;
 
634
                                    if(event.key === Qt.Key_Down && historyPosition < calculationHistory.getContents().count)
 
635
                                        historyPosition++;
 
636
                                    if(historyPosition !== calculationHistory.getContents().count) {
 
637
                                        isUsingHistory = true;
 
638
                                        clearFormula();
 
639
                                        formulaPush(calculationHistory.getContents().get(historyPosition).formula);
 
640
                                    }
 
641
                                    else if(isUsingHistory)
 
642
                                    {
 
643
                                        clearFormula();
 
644
                                        formulaPush(lastWrittenFormula);
 
645
                                        isUsingHistory = false;
 
646
                                    }
 
647
                                }
 
648
 
622
649
                                keyboardLoader.item.pressedKey = event.key;
623
650
                                keyboardLoader.item.pressedKeyText = event.text;
624
651
                            } else if (event.modifiers & Qt.ControlModifier) {
698
725
                                displayedInputText = shortFormula;
699
726
                            }
700
727
 
 
728
                        onTextChanged: {
 
729
                            if(! isUsingHistory) {
 
730
                                lastWrittenFormula = textInputField.text;
 
731
                            }
 
732
                        }
 
733
 
701
734
                        SequentialAnimation {
702
735
                            id: errorAnimation
703
736
                            running: false