Fix RefCell borrow conflict when toggling IME on Windows (#7529)
* Fix RefCell borrow conflict when toggling IME on Windows When IME is active, the `key` function was holding a borrow on the window's inner RefCell while calling `TranslateMessage`. This Windows API can trigger other window messages (like WM_SIZE) via `CtfImeCreateInputContext`, which then attempt to borrow the same RefCell, causing a panic with "RefCell already borrowed". Similarly, `ime_set_context` was holding a borrow while calling `DefWindowProcW`, which can also trigger recursive window messages. Fix by dropping the borrow prior to triggering potentially recursive calls. Fixes the crash that occurred when toggling IME (e.g., pressing Hankaku/Zenkaku key) after splitting a pane on Windows.
This commit is contained in:
1 parent
093bf6bf2b
commit
900bab10d6
1 file changed
+14
-4
@@ -2068,14 +2068,19 @@ unsafe fn ime_set_context(
|
||||
wparam: WPARAM,
|
||||
lparam: LPARAM,
|
||||
) -> Option<LRESULT> {
|
||||
let inner = rc_from_hwnd(hwnd)?;
|
||||
let inner = inner.borrow_mut();
|
||||
let use_system_rendering = {
|
||||
let inner = rc_from_hwnd(hwnd)?;
|
||||
let inner = inner.borrow();
|
||||
inner.config.ime_preedit_rendering == ImePreeditRendering::System
|
||||
};
|
||||
|
||||
if inner.config.ime_preedit_rendering == ImePreeditRendering::System {
|
||||
if use_system_rendering {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Don't show system CompositionWindow because application itself draws it
|
||||
// Don't show system CompositionWindow because application itself draws it.
|
||||
// Note: DefWindowProcW may trigger other window messages, so we must
|
||||
// release the borrow before calling it.
|
||||
let lparam = lparam & !(ISC_SHOWUICOMPOSITIONWINDOW as LPARAM);
|
||||
let result = DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||
Some(result)
|
||||
@@ -2523,6 +2528,11 @@ unsafe fn key(hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM) -> Option<L
|
||||
// or `ime_endcomposition` when it completes.
|
||||
|
||||
if msg == WM_KEYDOWN {
|
||||
// Release the borrow before calling translate_message:
|
||||
// TranslateMessage can trigger other window messages (like WM_SIZE)
|
||||
// via CtfImeCreateInputContext, which would otherwise cause a
|
||||
// RefCell borrow conflict while inner is still borrowed.
|
||||
drop(inner);
|
||||
// Explicitly allow the built-in translation to occur for the IME
|
||||
translate_message(hwnd, msg, wparam, lparam);
|
||||
return Some(0);
|
||||
|
||||
Reference in new issue
Block a user