Skip to content

Commit

Permalink
Merge pull request #20 from kou-yeung/feature/fix_firefox68_bug_#19
Browse files Browse the repository at this point in the history
Feature/fix firefox68 bug #19
  • Loading branch information
kou-yeung authored Jul 13, 2019
2 parents 7ab81ad + c93c617 commit c6e6450
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Assets/WebGLSupport/WebGLInput/WebGLInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class WebGLInputPlugin
[DllImport("__Internal")]
public static extern void WebGLInputText(int id, string text);

[DllImport("__Internal")]
public static extern bool WebGLInputIsFocus(int id);

[DllImport("__Internal")]
public static extern void WebGLInputDelete(int id);
#else
Expand All @@ -75,6 +78,7 @@ public static void WebGLInputOnEditEnd(int id, Action<int, string> cb) { }
public static void WebGLInputSetSelectionRange(int id, int start, int end) { }
public static void WebGLInputMaxLength(int id, int maxlength) { }
public static void WebGLInputText(int id, string text) { }
public static bool WebGLInputIsFocus(int id) { return false; }
public static void WebGLInputDelete(int id) { }
#endif
}
Expand Down Expand Up @@ -176,6 +180,7 @@ void DeactivateInputField()
WebGLInputPlugin.WebGLInputDelete(id);
input.DeactivateInputField();
instances.Remove(id);
id = -1; // reset id to -1;
WebGLWindow.OnBlurEvent -= OnWindowBlur;
}

Expand Down Expand Up @@ -250,6 +255,10 @@ void Update()
if (!instances.ContainsKey(id))
{
OnSelect();
} else if(!WebGLInputPlugin.WebGLInputIsFocus(id))
{
// focus this id
WebGLInputPlugin.WebGLInputFocus(id);
}

var start = WebGLInputPlugin.WebGLInputSelectionStart(id);
Expand Down
13 changes: 8 additions & 5 deletions Assets/WebGLSupport/WebGLInput/WebGLInput.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var WebGLInput = {
input.style.cursor = "default";
input.spellcheck = false;
input.value = Pointer_stringify(text);
input.style.fontSize = fontsize;
input.style.fontSize = fontsize + "px";
input.setSelectionRange(0, input.value.length);

if(isPassword){
Expand Down Expand Up @@ -66,6 +66,9 @@ var WebGLInput = {
Runtime.dynCall("vi", cb, [id]);
};
},
WebGLInputIsFocus: function (id) {
return instances[id] === document.activeElement;
},
WebGLInputOnValueChange:function(id, cb){
var input = instances[id];
input.oninput = function () {
Expand Down Expand Up @@ -105,11 +108,11 @@ var WebGLInput = {
input.value = Pointer_stringify(text);
},
WebGLInputDelete:function(id){
var input = instances[id];
input.parentNode.removeChild(input);
instances[id] = null;
var input = instances[id];
input.parentNode.removeChild(input);
instances[id] = null;
},
}

autoAddDeps(WebGLInput, '$instances');
autoAddDeps(WebGLInput, '$instances');
mergeInto(LibraryManager.library, WebGLInput);

0 comments on commit c6e6450

Please sign in to comment.