← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~nikwen/ubuntu-calculator-app/desktop-paste-support into lp:ubuntu-calculator-app

 

Niklas Wenzel has proposed merging lp:~nikwen/ubuntu-calculator-app/desktop-paste-support into lp:ubuntu-calculator-app with lp:~nikwen/ubuntu-calculator-app/delete-backspace-copy-fix as a prerequisite.

Commit message:
Add proper paste support on the desktop

Requested reviews:
  Ubuntu Calculator Developers (ubuntu-calculator-dev)

For more details, see:
https://code.launchpad.net/~nikwen/ubuntu-calculator-app/desktop-paste-support/+merge/266662

Add proper paste support on the desktop

(This is one of two MPs resulting from splitting https://code.launchpad.net/~nikwen/ubuntu-calculator-app/delete-copy-paste-fix/+merge/264621)
-- 
Your team Ubuntu Calculator Developers is requested to review the proposed merge of lp:~nikwen/ubuntu-calculator-app/desktop-paste-support into lp:ubuntu-calculator-app.
=== modified file 'app/ubuntu-calculator-app.qml'
--- app/ubuntu-calculator-app.qml	2015-08-02 12:21:10 +0000
+++ app/ubuntu-calculator-app.qml	2015-08-02 12:21:10 +0000
@@ -645,6 +645,53 @@
                                     var mimeData = Clipboard.newData();
                                     mimeData.text = textInputField.selectedText;
                                     Clipboard.push(mimeData);
+                                } else if (event.key === Qt.Key_V) { // Paste action
+                                    if (Clipboard.data.text && Clipboard.data.text !== "") {
+                                        var data = Clipboard.data.text;
+
+                                        // Get all accepted characters (i.e. those which can be entered) from the current keyboard
+                                        var acceptedBits = [];
+                                        for (var i = 0; i < keyboardLoader.item.children.length; i++) {
+                                            var model = keyboardLoader.item.children[i].keyboardModel;
+                                            if (model) {
+                                                for (var j = 0; j < model.length; j++) {
+                                                    var item = model[j];
+                                                    if (!item.action) {
+                                                        if (item.number)
+                                                            acceptedBits.push({ "chars": item.number, "push": item.number });
+                                                        if (item.pushText)
+                                                            acceptedBits.push({ "chars": item.pushText, "push": item.pushText }); // TODO: Accept both if different, brackets
+                                                        if (item.text)
+                                                            acceptedBits.push({ "chars": item.text, "push": item.pushText ? item.pushText : item.text });
+                                                    }
+                                                }
+                                            }
+                                        }
+
+                                        // Extract the part of the clipboard data which can be pasted
+                                        var paste = "";
+                                        var pos = 0;
+                                        while (pos < data.length) {
+                                            // Check if the string starts with an accepted string
+                                            for (i = 0; i < acceptedBits.length; i++) {
+                                                if (data.substring(pos, pos + (acceptedBits[i].chars.length ? acceptedBits[i].chars.length : 1)) === acceptedBits[i].chars.toString()) {
+                                                    paste += acceptedBits[i].push;
+                                                    pos += acceptedBits[i].chars.length ? acceptedBits[i].chars.length : 1;
+                                                    break;
+                                                }
+                                            }
+                                            // Skip one char if it could not be found
+                                            if (i === acceptedBits.length)
+                                                pos++;
+                                        }
+
+                                        // Push the paste string
+                                        formulaPush(paste);
+                                    } else {
+                                        console.log("Debug: paste failed as the clipboard contains no text");
+                                    }
+
+                                    scrollableView.scrollToBottom();
                                 }
                             }
                         }


Follow ups