Make IME code early return instead

This commit is contained in:
Adam Scott 2024-11-07 13:24:06 -05:00
parent 87318a2fb7
commit 75bf6df49a
No known key found for this signature in database
GPG key ID: F6BA2A0302E21A77

View file

@ -44,12 +44,15 @@ const GodotIME = {
}, },
ime_active: function (active) { ime_active: function (active) {
if (GodotIME.ime == null) {
return;
}
function focus_timer() { function focus_timer() {
GodotIME.active = true; GodotIME.active = true;
GodotIME.ime.focus(); GodotIME.ime.focus();
} }
if (GodotIME.ime) {
if (active) { if (active) {
GodotIME.ime.style.display = 'block'; GodotIME.ime.style.display = 'block';
setInterval(focus_timer, 100); setInterval(focus_timer, 100);
@ -58,11 +61,12 @@ const GodotIME = {
GodotConfig.canvas.focus(); GodotConfig.canvas.focus();
GodotIME.active = false; GodotIME.active = false;
} }
}
}, },
ime_position: function (x, y) { ime_position: function (x, y) {
if (GodotIME.ime) { if (GodotIME.ime == null) {
return;
}
const canvas = GodotConfig.canvas; const canvas = GodotConfig.canvas;
const rect = canvas.getBoundingClientRect(); const rect = canvas.getBoundingClientRect();
const rw = canvas.width / rect.width; const rw = canvas.width / rect.width;
@ -72,7 +76,6 @@ const GodotIME = {
GodotIME.ime.style.left = `${clx}px`; GodotIME.ime.style.left = `${clx}px`;
GodotIME.ime.style.top = `${cly}px`; GodotIME.ime.style.top = `${cly}px`;
}
}, },
init: function (ime_cb, key_cb, code, key) { init: function (ime_cb, key_cb, code, key) {
@ -84,7 +87,9 @@ const GodotIME = {
evt.preventDefault(); evt.preventDefault();
} }
function ime_event_cb(event) { function ime_event_cb(event) {
if (GodotIME.ime) { if (GodotIME.ime == null) {
return;
}
if (event.type === 'compositionstart') { if (event.type === 'compositionstart') {
ime_cb(0, null); ime_cb(0, null);
GodotIME.ime.innerHTML = ''; GodotIME.ime.innerHTML = '';
@ -99,7 +104,6 @@ const GodotIME = {
GodotIME.ime.innerHTML = ''; GodotIME.ime.innerHTML = '';
} }
} }
}
const ime = document.createElement('div'); const ime = document.createElement('div');
ime.className = 'ime'; ime.className = 'ime';
@ -133,10 +137,11 @@ const GodotIME = {
}, },
clear: function () { clear: function () {
if (GodotIME.ime) { if (GodotIME.ime == null) {
return;
}
GodotIME.ime.remove(); GodotIME.ime.remove();
GodotIME.ime = null; GodotIME.ime = null;
}
}, },
}, },
}; };