mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 06:01:14 +00:00
Make IME code early return instead
This commit is contained in:
parent
87318a2fb7
commit
75bf6df49a
1 changed files with 41 additions and 36 deletions
|
|
@ -44,35 +44,38 @@ 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);
|
} else {
|
||||||
} else {
|
GodotIME.ime.style.display = 'none';
|
||||||
GodotIME.ime.style.display = 'none';
|
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) {
|
||||||
const canvas = GodotConfig.canvas;
|
return;
|
||||||
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`;
|
|
||||||
}
|
}
|
||||||
|
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) {
|
init: function (ime_cb, key_cb, code, key) {
|
||||||
|
|
@ -84,20 +87,21 @@ const GodotIME = {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
}
|
}
|
||||||
function ime_event_cb(event) {
|
function ime_event_cb(event) {
|
||||||
if (GodotIME.ime) {
|
if (GodotIME.ime == null) {
|
||||||
if (event.type === 'compositionstart') {
|
return;
|
||||||
ime_cb(0, null);
|
}
|
||||||
GodotIME.ime.innerHTML = '';
|
if (event.type === 'compositionstart') {
|
||||||
} else if (event.type === 'compositionupdate') {
|
ime_cb(0, null);
|
||||||
const ptr = GodotRuntime.allocString(event.data);
|
GodotIME.ime.innerHTML = '';
|
||||||
ime_cb(1, ptr);
|
} else if (event.type === 'compositionupdate') {
|
||||||
GodotRuntime.free(ptr);
|
const ptr = GodotRuntime.allocString(event.data);
|
||||||
} else if (event.type === 'compositionend') {
|
ime_cb(1, ptr);
|
||||||
const ptr = GodotRuntime.allocString(event.data);
|
GodotRuntime.free(ptr);
|
||||||
ime_cb(2, ptr);
|
} else if (event.type === 'compositionend') {
|
||||||
GodotRuntime.free(ptr);
|
const ptr = GodotRuntime.allocString(event.data);
|
||||||
GodotIME.ime.innerHTML = '';
|
ime_cb(2, ptr);
|
||||||
}
|
GodotRuntime.free(ptr);
|
||||||
|
GodotIME.ime.innerHTML = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,10 +137,11 @@ const GodotIME = {
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function () {
|
clear: function () {
|
||||||
if (GodotIME.ime) {
|
if (GodotIME.ime == null) {
|
||||||
GodotIME.ime.remove();
|
return;
|
||||||
GodotIME.ime = null;
|
|
||||||
}
|
}
|
||||||
|
GodotIME.ime.remove();
|
||||||
|
GodotIME.ime = null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue