mirror of
https://github.com/penpot/penpot.git
synced 2026-07-02 12:25:42 +00:00
🐛 Fix crash on composition update when pressing Esc on a IME (#10479)
This commit is contained in:
parent
2d4a24bf97
commit
e6a49adfbc
@ -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
|
||||
|
||||
@ -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(()),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user