🐛 Fix crash on composition update when pressing Esc on a IME (#10479)

This commit is contained in:
Belén Albeza 2026-06-30 13:55:06 +02:00 committed by GitHub
parent 2d4a24bf97
commit e6a49adfbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View File

@ -81,8 +81,10 @@
(when-not composing?
(reset! composing? true))
;; IME cancel (e.g. Escape on Linux ibus-mozc) fires compositionupdate
;; with an empty string; that must reach WASM to clear the preview text.
(let [data (.-data event)]
(when data
(when (some? data)
(text-editor/text-editor-composition-update data)
(sync-wasm-text-editor-content!)
(wasm.api/request-render "text-composition"))
@ -93,13 +95,12 @@
(mf/use-fn
(fn [^js event]
(reset! composing? false)
(let [data (.-data event)]
(when data
(text-editor/text-editor-composition-end data)
(sync-wasm-text-editor-content!)
(wasm.api/request-render "text-composition"))
(when-let [node (mf/ref-val contenteditable-ref)]
(set! (.-textContent node) "")))))
(let [data (or (.-data event) "")]
(text-editor/text-editor-composition-end data)
(sync-wasm-text-editor-content!)
(wasm.api/request-render "text-composition"))
(when-let [node (mf/ref-val contenteditable-ref)]
(set! (.-textContent node) ""))))
on-paste
(mf/use-fn

View File

@ -324,7 +324,7 @@ pub extern "C" fn text_editor_composition_start() -> Result<()> {
#[no_mangle]
#[wasm_error]
pub extern "C" fn text_editor_composition_end() -> Result<()> {
let bytes = crate::mem::bytes();
let bytes = crate::mem::bytes_or_empty();
let text = match String::from_utf8(bytes) {
Ok(text) => text,
Err(_) => return Ok(()),
@ -380,7 +380,7 @@ pub extern "C" fn text_editor_composition_end() -> Result<()> {
#[no_mangle]
#[wasm_error]
pub extern "C" fn text_editor_composition_update() -> Result<()> {
let bytes = crate::mem::bytes();
let bytes = crate::mem::bytes_or_empty();
let text = match String::from_utf8(bytes) {
Ok(text) => text,
Err(_) => return Ok(()),