diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js index bd90e3220..35d7fe74c 100644 --- a/loleaflet/src/control/Control.LokDialog.js +++ b/loleaflet/src/control/Control.LokDialog.js @@ -288,7 +288,7 @@ L.Control.LokDialog = L.Control.extend({ this._dialogs[e.id].cursorVisible = e.visible === 'true'; if (this._dialogs[e.id].cursorVisible) { $('#' + strId + '-cursor').css({display: 'block'}); - this._map._onLostFocus(); + this._map.onEditorLostFocus(this); } else { $('#' + strId + '-cursor').css({display: 'none'}); diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 8ef2dce92..a6efdb86d 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -2656,7 +2656,14 @@ L.TileLayer = L.GridLayer.extend({ _onPaste: function (e) { e = e.originalEvent; - this._map._clip.paste(e); + if (!this._map._activeDialog) { + // Paste in document + this._map._clip.paste(e); + } else { + // Paste in dialog + e.usePasteKeyEvent = true; + this._map._clip.paste(e); + } }, _onDragOver: function (e) { diff --git a/loleaflet/src/map/Clipboard.js b/loleaflet/src/map/Clipboard.js index af664388d..9afb59ee3 100644 --- a/loleaflet/src/map/Clipboard.js +++ b/loleaflet/src/map/Clipboard.js @@ -196,7 +196,7 @@ L.Clipboard = L.Class.extend({ }; }, - dataTransferToDocument: function (dataTransfer, preferInternal, htmlText) { + dataTransferToDocument: function (dataTransfer, preferInternal, htmlText, usePasteKeyEvent) { // Look for our HTML meta magic. // cf. ClientSession.cpp /textselectioncontent:/ @@ -273,12 +273,19 @@ L.Clipboard = L.Class.extend({ var that = this; this._doAsyncDownload('POST', destination, formData, - function() { - console.log('Posted ' + content.size + ' bytes successfully'); - that._map._socket.sendMessage('uno .uno:Paste'); - }, - function(progress) { return progress; } - ); + function() { + console.log('Posted ' + content.size + ' bytes successfully'); + if (usePasteKeyEvent) { + // paste into dialog + var KEY_PASTE = 1299; + that._map._clipboardContainer._sendKeyEvent(0, KEY_PASTE); + } else { + // paste into document + that._map._socket.sendMessage('uno .uno:Paste'); + } + }, + function(progress) { return progress; } + ); } else { console.log('Nothing we can paste on the clipboard'); } @@ -498,7 +505,8 @@ L.Clipboard = L.Class.extend({ console.log('Paste'); if (ev.clipboardData) { // Standard ev.preventDefault(); - this.dataTransferToDocument(ev.clipboardData, /* preferInternal = */ true); + var usePasteKeyEvent = ev.usePasteKeyEvent; + this.dataTransferToDocument(ev.clipboardData, /* preferInternal = */ true, null, usePasteKeyEvent); this._map._clipboardContainer._abortComposition(); this._clipboardSerial++; } diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 8f755afa1..78602aa4e 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -1169,8 +1169,8 @@ L.Map = L.Evented.extend({ }, map.options.outOfFocusTimeoutSecs * 1000); }, - // The editor got focus (probably a dialog closed or user clicked to edit). - _onEditorLostFocus: function() { + // The editor lost focus (probably a dialog was created). + onEditorLostFocus: function onEditorLostFocus(dialog) { if (!this._loaded) { return; } var doclayer = this._docLayer; @@ -1179,11 +1179,15 @@ L.Map = L.Evented.extend({ doclayer._isFocused = false; doclayer._updateCursorAndOverlay(); } + + if (dialog) { + this._activeDialog = dialog; + } }, // Our browser tab lost focus. _onLostFocus: function () { - this._onEditorLostFocus(); + this.onEditorLostFocus(); this._deactivate(); }, @@ -1204,6 +1208,7 @@ L.Map = L.Evented.extend({ }, 300); } + this._activeDialog = null; }, // Our browser tab lost focus.