mirror of
https://github.com/penpot/penpot.git
synced 2026-08-28 15:48:52 +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?
|
(when-not composing?
|
||||||
(reset! composing? true))
|
(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)]
|
(let [data (.-data event)]
|
||||||
(when data
|
(when (some? data)
|
||||||
(text-editor/text-editor-composition-update data)
|
(text-editor/text-editor-composition-update data)
|
||||||
(sync-wasm-text-editor-content!)
|
(sync-wasm-text-editor-content!)
|
||||||
(wasm.api/request-render "text-composition"))
|
(wasm.api/request-render "text-composition"))
|
||||||
@ -93,13 +95,12 @@
|
|||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [^js event]
|
(fn [^js event]
|
||||||
(reset! composing? false)
|
(reset! composing? false)
|
||||||
(let [data (.-data event)]
|
(let [data (or (.-data event) "")]
|
||||||
(when data
|
(text-editor/text-editor-composition-end data)
|
||||||
(text-editor/text-editor-composition-end data)
|
(sync-wasm-text-editor-content!)
|
||||||
(sync-wasm-text-editor-content!)
|
(wasm.api/request-render "text-composition"))
|
||||||
(wasm.api/request-render "text-composition"))
|
(when-let [node (mf/ref-val contenteditable-ref)]
|
||||||
(when-let [node (mf/ref-val contenteditable-ref)]
|
(set! (.-textContent node) ""))))
|
||||||
(set! (.-textContent node) "")))))
|
|
||||||
|
|
||||||
on-paste
|
on-paste
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
|||||||
@ -324,7 +324,7 @@ pub extern "C" fn text_editor_composition_start() -> Result<()> {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[wasm_error]
|
#[wasm_error]
|
||||||
pub extern "C" fn text_editor_composition_end() -> Result<()> {
|
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) {
|
let text = match String::from_utf8(bytes) {
|
||||||
Ok(text) => text,
|
Ok(text) => text,
|
||||||
Err(_) => return Ok(()),
|
Err(_) => return Ok(()),
|
||||||
@ -380,7 +380,7 @@ pub extern "C" fn text_editor_composition_end() -> Result<()> {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[wasm_error]
|
#[wasm_error]
|
||||||
pub extern "C" fn text_editor_composition_update() -> Result<()> {
|
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) {
|
let text = match String::from_utf8(bytes) {
|
||||||
Ok(text) => text,
|
Ok(text) => text,
|
||||||
Err(_) => return Ok(()),
|
Err(_) => return Ok(()),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user