summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Scott <ascott.ca@gmail.com>2024-11-07 13:24:06 -0500
committerAdam Scott <ascott.ca@gmail.com>2024-11-07 13:27:29 -0500
commit75bf6df49a6fa87c718f4052343a4b6ff4de574c (patch)
treeaf11dd1cebdf67f0b7fcbb0cffdd0eabb8264230
parent87318a2fb7fffeb72adca934e31915be077c3d1f (diff)
downloadredot-engine-75bf6df49a6fa87c718f4052343a4b6ff4de574c.tar.gz
Make IME code early return instead
-rw-r--r--platform/web/js/libs/library_godot_input.js77
1 files changed, 41 insertions, 36 deletions
diff --git a/platform/web/js/libs/library_godot_input.js b/platform/web/js/libs/library_godot_input.js
index 6e3b97023d..dfab882fd3 100644
--- a/platform/web/js/libs/library_godot_input.js
+++ b/platform/web/js/libs/library_godot_input.js
@@ -44,35 +44,38 @@ const GodotIME = {
},
ime_active: function (active) {
+ if (GodotIME.ime == null) {
+ return;
+ }
+
function focus_timer() {
GodotIME.active = true;
GodotIME.ime.focus();
}
- if (GodotIME.ime) {
- if (active) {
- GodotIME.ime.style.display = 'block';
- setInterval(focus_timer, 100);
- } else {
- GodotIME.ime.style.display = 'none';
- GodotConfig.canvas.focus();
- GodotIME.active = false;
- }
+ if (active) {
+ GodotIME.ime.style.display = 'block';
+ setInterval(focus_timer, 100);
+ } else {
+ GodotIME.ime.style.display = 'none';
+ GodotConfig.canvas.focus();
+ GodotIME.active = false;
}
},
ime_position: function (x, y) {
- if (GodotIME.ime) {
- const canvas = GodotConfig.canvas;
- const rect = canvas.getBoundingClientRect();
- const rw = canvas.width / rect.width;
- const rh = canvas.height / rect.height;
- const clx = (x / rw) + rect.x;
- const cly = (y / rh) + rect.y;
-
- GodotIME.ime.style.left = `${clx}px`;
- GodotIME.ime.style.top = `${cly}px`;
+ if (GodotIME.ime == null) {
+ return;
}
+ const canvas = GodotConfig.canvas;
+ const rect = canvas.getBoundingClientRect();
+ const rw = canvas.width / rect.width;
+ const rh = canvas.height / rect.height;
+ const clx = (x / rw) + rect.x;
+ const cly = (y / rh) + rect.y;
+
+ GodotIME.ime.style.left = `${clx}px`;
+ GodotIME.ime.style.top = `${cly}px`;
},
init: function (ime_cb, key_cb, code, key) {
@@ -84,20 +87,21 @@ const GodotIME = {
evt.preventDefault();
}
function ime_event_cb(event) {
- if (GodotIME.ime) {
- if (event.type === 'compositionstart') {
- ime_cb(0, null);
- GodotIME.ime.innerHTML = '';
- } else if (event.type === 'compositionupdate') {
- const ptr = GodotRuntime.allocString(event.data);
- ime_cb(1, ptr);
- GodotRuntime.free(ptr);
- } else if (event.type === 'compositionend') {
- const ptr = GodotRuntime.allocString(event.data);
- ime_cb(2, ptr);
- GodotRuntime.free(ptr);
- GodotIME.ime.innerHTML = '';
- }
+ if (GodotIME.ime == null) {
+ return;
+ }
+ if (event.type === 'compositionstart') {
+ ime_cb(0, null);
+ GodotIME.ime.innerHTML = '';
+ } else if (event.type === 'compositionupdate') {
+ const ptr = GodotRuntime.allocString(event.data);
+ ime_cb(1, ptr);
+ GodotRuntime.free(ptr);
+ } else if (event.type === 'compositionend') {
+ const ptr = GodotRuntime.allocString(event.data);
+ ime_cb(2, ptr);
+ GodotRuntime.free(ptr);
+ GodotIME.ime.innerHTML = '';
}
}
@@ -133,10 +137,11 @@ const GodotIME = {
},
clear: function () {
- if (GodotIME.ime) {
- GodotIME.ime.remove();
- GodotIME.ime = null;
+ if (GodotIME.ime == null) {
+ return;
}
+ GodotIME.ime.remove();
+ GodotIME.ime = null;
},
},
};