Skip to content

Commit 49a9a3a

Browse files
committed
browser: ts: Clipboard.js: convert dataTransferToDocument()
Signed-off-by: Dennis Francis <[email protected]> Change-Id: I06398740734c015908b657bf770d63f7eaa9b9a8
1 parent 494202a commit 49a9a3a

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

browser/src/app/ClipboardBase.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,53 @@ class CoolClipboardBase extends BaseClass {
545545
return true;
546546
}
547547

548+
// Returns true if it finished synchronously, and false if it has started an async operation
549+
// that will likely end at a later time (required to avoid closing progress bar in paste(ev))
550+
// FIXME: This comment is a lie if dataTransferToDocumentFallback is called, as it calls _doAsyncDownload
548551
public dataTransferToDocument(
549552
dataTransfer: DataTransfer,
550553
preferInternal: boolean,
551554
htmlText: string,
552555
usePasteKeyEvent: boolean,
553556
): boolean {
554-
console.assert(false, 'This should not be called!');
555-
return false;
557+
// Look for our HTML meta magic.
558+
// cf. ClientSession.cpp /textselectioncontent:/
559+
560+
const meta = this._getMetaOrigin(
561+
htmlText,
562+
'<div id="meta-origin" data-coolorigin="',
563+
);
564+
const id = this.getMetaPath(0);
565+
const idOld = this.getMetaPath(1);
566+
567+
// for the paste, we always prefer the internal LOK's copy/paste
568+
if (
569+
preferInternal === true &&
570+
((id !== '' && meta.indexOf(id) >= 0) ||
571+
(idOld !== '' && meta.indexOf(idOld) >= 0))
572+
) {
573+
// Home from home: short-circuit internally.
574+
window.app.console.log('short-circuit, internal paste');
575+
this._doInternalPaste(this._map, usePasteKeyEvent);
576+
return true;
577+
}
578+
579+
// Do we have a remote Online we can suck rich data from ?
580+
if (meta !== '') {
581+
window.app.console.log(
582+
'Transfer between servers\n\t"' + meta + '" vs. \n\t"' + id + '"',
583+
);
584+
this._dataTransferDownloadAndPasteAsync(meta, htmlText);
585+
return false; // just started async operation - did not finish yet
586+
}
587+
588+
// Fallback.
589+
this.dataTransferToDocumentFallback(
590+
dataTransfer,
591+
htmlText,
592+
usePasteKeyEvent,
593+
);
594+
return true;
556595
}
557596

558597
private async _sendToInternalClipboard(

browser/src/map/Clipboard.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,6 @@ window.L.Clipboard = class Clipboard extends CoolClipboardBase {
2424
super(map);
2525
}
2626

27-
// Returns true if it finished synchronously, and false if it has started an async operation
28-
// that will likely end at a later time (required to avoid closing progress bar in paste(ev))
29-
// FIXME: This comment is a lie if dataTransferToDocumentFallback is called, as it calls _doAsyncDownload
30-
dataTransferToDocument(dataTransfer, preferInternal, htmlText, usePasteKeyEvent) {
31-
// Look for our HTML meta magic.
32-
// cf. ClientSession.cpp /textselectioncontent:/
33-
34-
var meta = this._getMetaOrigin(htmlText, '<div id="meta-origin" data-coolorigin="');
35-
var id = this.getMetaPath(0);
36-
var idOld = this.getMetaPath(1);
37-
38-
// for the paste, we always prefer the internal LOK's copy/paste
39-
if (preferInternal === true &&
40-
((id !== '' && meta.indexOf(id) >= 0) || (idOld !== '' && meta.indexOf(idOld) >= 0)))
41-
{
42-
// Home from home: short-circuit internally.
43-
window.app.console.log('short-circuit, internal paste');
44-
this._doInternalPaste(this._map, usePasteKeyEvent);
45-
return true;
46-
}
47-
48-
// Do we have a remote Online we can suck rich data from ?
49-
if (meta !== '')
50-
{
51-
window.app.console.log('Transfer between servers\n\t"' + meta + '" vs. \n\t"' + id + '"');
52-
this._dataTransferDownloadAndPasteAsync(meta, htmlText);
53-
return false; // just started async operation - did not finish yet
54-
}
55-
56-
// Fallback.
57-
this.dataTransferToDocumentFallback(dataTransfer, htmlText, usePasteKeyEvent);
58-
return true;
59-
}
60-
6127
async _sendToInternalClipboard(content) {
6228
if (window.ThisIsTheiOSApp) {
6329
await window.webkit.messageHandlers.clipboard.postMessage(`sendToInternal ${await content.text()}`); // no need to base64 in this direction...

0 commit comments

Comments
 (0)