Consolidate HTML5 clipboard logic

This commit is contained in:
Joshua Granick
2017-01-31 11:48:15 -08:00
parent 4bd00f2d0b
commit 3ede95dff4
2 changed files with 29 additions and 20 deletions

View File

@@ -730,6 +730,29 @@ class HTML5Window {
}
public function setClipboard (value:String):Void {
if (Browser.document.queryCommandEnabled ("copy")) {
var inputEnabled = enableTextEvents;
setEnableTextEvents (true); // create textInput if necessary
setEnableTextEvents (false);
var cacheText = textInput.value;
textInput.value = value;
Browser.document.execCommand ("copy");
textInput.value = cacheText;
setEnableTextEvents (inputEnabled);
}
}
public function setEnableTextEvents (value:Bool):Bool {
if (value) {

View File

@@ -2,14 +2,12 @@ package lime.system;
import lime._backend.native.NativeCFFI;
import lime.app.Application;
#if flash
import flash.desktop.Clipboard in FlashClipboard;
#elseif js
import lime._backend.html5.HTML5Window;
import js.Browser.document;
@:access(lime._backend.html5.HTML5Window)
#end
#if !lime_debug
@@ -18,6 +16,7 @@ import js.Browser.document;
#end
@:access(lime._backend.native.NativeCFFI)
@:access(lime.ui.Window)
class Clipboard {
@@ -61,30 +60,17 @@ class Clipboard {
#if (lime_cffi && !macro)
NativeCFFI.lime_clipboard_set_text (value);
return value;
#elseif flash
FlashClipboard.generalClipboard.setData (TEXT_FORMAT, value);
return value;
#elseif js
#elseif (js && html5)
_text = value;
#if html5 // HTML5 needs focus on <input> field for clipboard events to work
if (HTML5Window.textInput != null) {
var window = Application.current.window;
if (window != null) {
HTML5Window.textInput.focus();
HTML5Window.textInput.value = _text;
HTML5Window.textInput.select();
window.backend.setClipboard (value);
}
if (document.queryCommandEnabled("copy")) {
document.execCommand("copy");
}
#end
return value;
#end