From 2d956b4c3719699365630f16efec84e22c9a0cd0 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Wed, 29 May 2019 13:11:01 +0100 Subject: Add pasteresult: message to allow re-try with a different format. Change-Id: Ia3d7aacdcf2b819437eb2da68a79dd99ed7dca42 --- kit/ChildSession.cpp | 16 ++++++++++++-- loleaflet/src/layer/tile/TileLayer.js | 41 ++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 91a3ad296b..f4387d60d1 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -997,15 +997,19 @@ bool ChildSession::paste(const char* buffer, int length, const std::vector 0) { std::unique_lock lock(_docManager.getDocumentMutex()); @@ -1013,9 +1017,17 @@ bool ChildSession::paste(const char* buffer, int length, const std::vectorsetView(_viewId); LOG_TRC("Paste data of size " << size << " bytes and hash " << SpookyHash::Hash64(data, size, 0)); - if (!getLOKitDocument()->paste(mimeType.c_str(), data, size)) + success = getLOKitDocument()->paste(mimeType.c_str(), data, size); + if (!success) LOG_WRN("Paste failed " << getLOKitLastError()); } + if (success) + result += "success"; + else if (fallback) + result += "fallback"; + else + result += "fail"; + sendTextFrame(result); return true; } diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index b9a23067ab..71705148aa 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -493,6 +493,9 @@ L.TileLayer = L.GridLayer.extend({ else if (textMsg.startsWith('editor:')) { this._updateEditor(textMsg); } + else if (textMsg.startsWith('pasteresult:')) { + this._pasteResult(textMsg); + } else if (textMsg.startsWith('validitylistbutton:')) { this._onValidityListButtonMsg(textMsg); } @@ -2493,6 +2496,23 @@ L.TileLayer = L.GridLayer.extend({ return ''; }, + // Sometimes our smart-paste fails & we need to try again. + _pasteResult : function(textMsg) + { + textMsg = textMsg.substring('pasteresult:'.length + 1); + console.log('Paste state: ' + textMsg); + if (textMsg == 'fallback') { + if (this._pasteFallback != null) { + console.log('Paste failed- falling back to HTML'); + this._map._socket.sendMessage(this._pasteFallback); + } else { + console.log('No paste fallback present.'); + } + } + + this._pasteFallback = null; + }, + _dataTransferToDocument: function (dataTransfer, preferInternal) { // Look for our HTML meta magic. @@ -2511,6 +2531,9 @@ L.TileLayer = L.GridLayer.extend({ return; } + console.log('Resetting paste fallback'); + this._pasteFallback = null; + // Suck HTML content out of dataTransfer now while it feels like working. var content = this._readContentSync(dataTransfer); @@ -2541,10 +2564,12 @@ L.TileLayer = L.GridLayer.extend({ return; } - // Try Fetch the data directly ourselves instead. - if (meta != '') { + if (meta != '') { // in Smart server side paste mode ... // FIXME: really should short-circuit on the server. console.log('Doing async paste of data from remote origin\n\t"' + meta + '" is not\n\t"' + id + '"'); + + this._pasteFallback = content; + var tilelayer = this; var oReq = new XMLHttpRequest(); oReq.onload = function(e) { @@ -2556,18 +2581,24 @@ L.TileLayer = L.GridLayer.extend({ } else { console.log('Error code ' + oReq.status + ' fetching from URL "' + meta + '": ' + e + ' falling back to local.'); tilelayer._map._socket.sendMessage(content); + this._pasteFallback = null; } } oReq.onerror = function(e) { console.log('Error fetching from URL "' + meta + '": ' + e + ' falling back to local.'); tilelayer._map._socket.sendMessage(content); + this._pasteFallback = null; }; oReq.open('GET', meta); oReq.responseType = 'arraybuffer'; oReq.send(); // user abort - if they do stops paste. + } else if (content != null) { + console.log('Normal HTML, so smart paste not possible'); + tilelayer._map._socket.sendMessage(content); + this._pasteFallback = null; } else { - console.log('Received a paste but nothing on the clipboard'); + console.log('Nothing we can paste on the clipboard'); } }, @@ -2575,9 +2606,9 @@ L.TileLayer = L.GridLayer.extend({ // Try various content mime types var mimeTypes; if (this._docType === 'spreadsheet') { - // FIXME apparently we cannot paste the text/html or text/rtf as - // produced by LibreOffice in Calc from some reason mimeTypes = [ + ['text/rtf', 'text/rtf'], + ['text/html', 'text/html'], ['text/plain', 'text/plain;charset=utf-8'], ['Text', 'text/plain;charset=utf-8'] ]; -- cgit