loleaflet/src/core/Util.js                |   17 ++++++++++++
 loleaflet/src/map/Clipboard.js            |   41 ++++++++++++++++--------------
 loleaflet/src/map/handler/Map.Keyboard.js |   25 ++++++++++++++++++
 3 files changed, 65 insertions(+), 18 deletions(-)

New commits:
commit 457fc3d538aed7bc2bc41fd022399749f4c5a3e4
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Tue Aug 18 19:33:13 2020 +0530
Commit:     Michael Meeks <michael.me...@collabora.com>
CommitDate: Tue Sep 1 18:23:03 2020 +0200

    clipboard: leaflet: unformatted paste shortcut changed
    
    Problems:
    1: Browsers hard-code ctrl+shift+v as "paste without formatting" - ie. 
plain text
    We need access to the clipboard to get the rich data needed for 
paste-special,
    which we can only get security context /  access to with a ctrl-v keypress
    2: we cannot directly access the clipboard data with ctrl+shift+alt+v
    
    Solution:
    Externally copied data could not be pasted directly with paste special
    and unformatted paste due to no access to the clipboard data
    
    To access the data copied externally we rely on user to trigger paste event
    We use default browser shortcut for unformatted paste(ctrl+shift+v)
    this triggers a paste event
    
    for paste special we ask user to press ctrl+v with a popup and then
    if that popup is open and paste event is triggered we trigger paste special
    
    New shortcuts:
    Paste: ctrl+v
    unformatted Paste: ctrl+shift+v
    Paste special: ctrl+shift+alt+v
    
    Change-Id: Ib15c701f5e03123cb91e36d1c1d64f0c12aa9cfb
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100927
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/loleaflet/src/core/Util.js b/loleaflet/src/core/Util.js
index 596dfa756..b2900b62b 100644
--- a/loleaflet/src/core/Util.js
+++ b/loleaflet/src/core/Util.js
@@ -207,6 +207,23 @@ L.Util = {
                context.font = font;
                var metrics = context.measureText(text);
                return Math.floor(metrics.width);
+       },
+
+       replaceCtrlInMac: function(msg) {
+               if (navigator.appVersion.indexOf('Mac') != -1 || 
navigator.userAgent.indexOf('Mac') != -1) {
+                       var ctrl = /Ctrl/g;
+                       if (String.locale.startsWith('de') || 
String.locale.startsWith('dsb') || String.locale.startsWith('hsb')) {
+                               ctrl = /Strg/g;
+                       }
+                       if (String.locale.startsWith('lt')) {
+                               ctrl = /Vald/g;
+                       }
+                       if (String.locale.startsWith('sl')) {
+                               ctrl = /Krmilka/g;
+                       }
+                       return msg.replace(ctrl, '⌘');
+               }
+               return msg;
        }
 };
 
diff --git a/loleaflet/src/map/Clipboard.js b/loleaflet/src/map/Clipboard.js
index ede448410..85925f4a2 100644
--- a/loleaflet/src/map/Clipboard.js
+++ b/loleaflet/src/map/Clipboard.js
@@ -264,8 +264,15 @@ L.Clipboard = L.Class.extend({
                                that._doAsyncDownload(
                                        'POST', dest, formData,
                                        function() {
-                                               console.log('up-load done, now 
paste');
-                                               
that._map._socket.sendMessage('uno .uno:Paste');
+                                               if (this.pasteSpecialVex && 
this.pasteSpecialVex.isOpen) {
+                                                       
vex.close(this.pasteSpecialVex);
+                                                       console.log('up-load 
done, now paste special');
+                                                       
that.map._socket.sendMessage('uno .uno:PasteSpecial');
+                                               } else {
+                                                       console.log('up-load 
done, now paste');
+                                                       
that._map._socket.sendMessage('uno .uno:Paste');
+                                               }
+
                                        },
                                        function(progress) { return 50 + 
progress/2; }
                                );
@@ -292,8 +299,15 @@ L.Clipboard = L.Class.extend({
                                that._doAsyncDownload(
                                        'POST', dest, formData,
                                        function() {
-                                               console.log('up-load of 
fallback done, now paste');
-                                               
that._map._socket.sendMessage('uno .uno:Paste');
+                                               if (this.pasteSpecialVex && 
this.pasteSpecialVex.isOpen) {
+                                                       
vex.close(this.pasteSpecialVex);
+                                                       console.log('up-load of 
fallback done, now paste special');
+                                                       
that.map._socket.sendMessage('uno .uno:PasteSpecial');
+                                               } else {
+                                                       console.log('up-load of 
fallback done, now paste');
+                                                       
that._map._socket.sendMessage('uno .uno:Paste');
+                                               }
+
                                        },
                                        function(progress) { return 50 + 
progress/2; },
                                        function() {
@@ -665,6 +679,9 @@ L.Clipboard = L.Class.extend({
                        // paste into dialog
                        var KEY_PASTE = 1299;
                        map._textInput._sendKeyEvent(0, KEY_PASTE);
+               } else if (this.pasteSpecialVex && this.pasteSpecialVex.isOpen) 
{
+                       this.pasteSpecialVex.close();
+                       map._socket.sendMessage('uno .uno:PasteSpecial');
                } else {
                        // paste into document
                        map._socket.sendMessage('uno .uno:Paste');
@@ -678,7 +695,7 @@ L.Clipboard = L.Class.extend({
        paste: function(ev) {
                console.log('Paste');
 
-               if (isAnyVexDialogActive() && !this._map.hasFocus())
+               if (isAnyVexDialogActive() && !(this.pasteSpecialVex && 
this.pasteSpecialVex.isOpen))
                        return;
 
                if ($('.annotation-active').length > 0 && !this._map.hasFocus())
@@ -821,19 +838,7 @@ L.Clipboard = L.Class.extend({
                        msg = _('<p>Please use the copy/paste buttons on your 
on-screen keyboard.</p>');
                } else {
                        msg = _('<p>Your browser has very limited access to the 
clipboard, so use these keyboard shortcuts:<ul><li><b>Ctrl+C</b>: For 
copying.</li><li><b>Ctrl+X</b>: For cutting.</li><li><b>Ctrl+V</b>: For 
pasting.</li></ul></p>');
-                       if (navigator.appVersion.indexOf('Mac') != -1 || 
navigator.userAgent.indexOf('Mac') != -1) {
-                               var ctrl = /Ctrl/g;
-                               if (String.locale.startsWith('de') || 
String.locale.startsWith('dsb') || String.locale.startsWith('hsb')) {
-                                       ctrl = /Strg/g;
-                               }
-                               if (String.locale.startsWith('lt')) {
-                                       ctrl = /Vald/g;
-                               }
-                               if (String.locale.startsWith('sl')) {
-                                       ctrl = /Krmilka/g;
-                               }
-                               msg = msg.replace(ctrl, '⌘');
-                       }
+                       msg = L.Util.replaceCtrlInMac(msg);
                }
                vex.dialog.alert({
                        unsafeMessage: msg,
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js 
b/loleaflet/src/map/handler/Map.Keyboard.js
index c3f578612..dd735ab5f 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -7,6 +7,8 @@
  * at TextInput.
  */
 
+ /* global vex _ */
+
 L.Map.mergeOptions({
        keyboard: true,
        keyboardPanOffset: 20,
@@ -416,6 +418,29 @@ L.Map.Keyboard = L.Handler.extend({
                        return true;
                }
 
+               // Handles paste special
+               if (e.ctrlKey && e.shiftKey && e.altKey && (e.key === 'v' || 
e.key === 'V')) {
+                       var map = this._map;
+                       var msg = _('<p>Your browser has very limited access to 
the clipboard, so now press:</li><li><b>Ctrl+V</b>: To open paste special 
menu.</li></ul></p><p>Close popup to ignore paste special</p>');
+                       msg = L.Util.replaceCtrlInMac(msg);
+                       this._map._clip.pasteSpecialVex = vex.open({
+                               unsafeContent: msg,
+                               showCloseButton: true,
+                               escapeButtonCloses: true,
+                               overlayClosesOnClick: false,
+                               buttons: {},
+                               afterOpen: function() {
+                                       map.focus();
+                               }
+                       });
+                       return true;
+               }
+
+               // Handles unformatted paste
+               if (e.ctrlKey && e.shiftKey && (e.key === 'v' || e.key === 
'V')) {
+                       return true;
+               }
+
                if (e.ctrlKey && (e.key === 'k' || e.key === 'K')) {
                        this._map.showHyperlinkDialog();
                        e.preventDefault();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to