Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 14f2bc7

Browse files
authored
Merge pull request #184 from UnityTech/iphoneplus_view
webgl copy-paste text
2 parents 6ed6fe5 + 2dc4567 commit 14f2bc7

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Runtime/Plugins/platform/webgl/webgl.jslib

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ var UIWidgetsLibrary = {
5656

5757
UIWidgetsMessageSetObjectName: function (name) {
5858
UIWidgetsPlugin.getMessageManager().setObjectName(Pointer_stringify(name));
59+
},
60+
61+
UIWidgetsCopyTextToClipboard: function (text) {
62+
var el = document.createElement('textarea');
63+
el.value = Pointer_stringify(text);
64+
el.setAttribute('readonly', '');
65+
el.style = {
66+
position: 'fixed',
67+
left: '-9999px',
68+
};
69+
document.body.appendChild(el);
70+
el.select();
71+
document.execCommand('copy');
72+
document.body.removeChild(el);
5973
}
6074
};
6175

Runtime/service/clipboard.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.InteropServices;
12
using RSG;
23
using UnityEngine;
34

@@ -29,13 +30,23 @@ public static IPromise<ClipboardData> getData(string format) {
2930

3031
public class UnityGUIClipboard : Clipboard {
3132
protected override IPromise setClipboardData(ClipboardData data) {
33+
#if UNITY_WEBGL
34+
UIWidgetsCopyTextToClipboard(data.text);
35+
#else
3236
GUIUtility.systemCopyBuffer = data.text;
37+
#endif
38+
3339
return Promise.Resolved();
3440
}
3541

3642
protected override IPromise<ClipboardData> getClipboardData(string format) {
3743
var data = new ClipboardData(text: GUIUtility.systemCopyBuffer);
3844
return Promise<ClipboardData>.Resolved(data);
3945
}
46+
47+
#if UNITY_WEBGL
48+
[DllImport ("__Internal")]
49+
internal static extern void UIWidgetsCopyTextToClipboard(string text);
50+
#endif
4051
}
4152
}

Samples/UIWidgetSample/HoverRecognizerSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override Widget build(BuildContext context) {
3535
return new Scaffold(
3636
appBar: new AppBar(
3737
title: new Center(
38-
child: new Text("Test Hover Widget")
38+
child: new SelectableText("Test Hover Widget")
3939
)
4040
),
4141
body: new Card(

0 commit comments

Comments
 (0)