From 9a6688bdfb87a38615239a2a05ac4061bf14fdbe Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 22 Dec 2023 18:41:43 +0100 Subject: [PATCH] Fix panic when deploying emoji picker (character palette) The panic was caused by Cocoa synchronously invoking the `selected_text_range` method on the registered input handler while we already had a borrow of the app. This commit fixes this issue by showing the character palette on the next tick of the loop (we've had this problem in other spots too and used the same technique). --- crates/gpui2/src/platform/mac/window.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/gpui2/src/platform/mac/window.rs b/crates/gpui2/src/platform/mac/window.rs index 12189e198a..a1fda0b75d 100644 --- a/crates/gpui2/src/platform/mac/window.rs +++ b/crates/gpui2/src/platform/mac/window.rs @@ -886,11 +886,16 @@ impl PlatformWindow for MacWindow { } fn show_character_palette(&self) { - unsafe { - let app = NSApplication::sharedApplication(nil); - let window = self.0.lock().native_window; - let _: () = msg_send![app, orderFrontCharacterPalette: window]; - } + let this = self.0.lock(); + let window = this.native_window; + this.executor + .spawn(async move { + unsafe { + let app = NSApplication::sharedApplication(nil); + let _: () = msg_send![app, orderFrontCharacterPalette: window]; + } + }) + .detach(); } fn minimize(&self) {