diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rs index bab65dcba3..5c3e709f86 100644 --- a/crates/editor/src/test/editor_test_context.rs +++ b/crates/editor/src/test/editor_test_context.rs @@ -241,7 +241,7 @@ impl EditorTestContext { // so you can use it to test detailed timing pub fn simulate_keystroke(&mut self, keystroke_text: &str) { let keyboard_mapper = self.keyboard_mapper(); - let keystroke = Keystroke::parse(keystroke_text, keyboard_mapper).unwrap(); + let keystroke = Keystroke::parse(keystroke_text, keyboard_mapper.as_ref()).unwrap(); self.cx.dispatch_keystroke(self.window, keystroke); } diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index 3015beb57f..86be5acc36 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -25,7 +25,6 @@ pub struct TestAppContext { pub dispatcher: TestDispatcher, test_platform: Rc, text_system: Arc, - keyboard_mapper: Rc>, fn_name: Option<&'static str>, on_quit: Rc>>>, } @@ -122,7 +121,6 @@ impl TestAppContext { let asset_source = Arc::new(()); let http_client = http_client::FakeHttpClient::with_404_response(); let text_system = Arc::new(TextSystem::new(platform.text_system())); - let keyboard_mapper = std::rc::Rc::new(platform.keyboard_mapper()); Self { app: App::new_app(platform.clone(), asset_source, http_client), @@ -131,7 +129,6 @@ impl TestAppContext { dispatcher: dispatcher.clone(), test_platform: platform, text_system, - keyboard_mapper, fn_name, on_quit: Rc::new(RefCell::new(Vec::default())), } @@ -401,8 +398,8 @@ impl TestAppContext { } /// Returns the current keyboard mapper for this platform. - pub fn keyboard_mapper(&self) -> Rc> { - self.keyboard_mapper.clone() + pub fn keyboard_mapper(&self) -> Rc { + self.test_platform.keyboard_mapper() } /// simulate_keystrokes takes a space-separated list of keys to type. diff --git a/crates/gpui/src/interactive.rs b/crates/gpui/src/interactive.rs index 3a266960f2..6ed0f997a1 100644 --- a/crates/gpui/src/interactive.rs +++ b/crates/gpui/src/interactive.rs @@ -541,11 +541,11 @@ mod test { let keyboard_mapper = cx.keyboard_mapper(); cx.dispatch_keystroke( *window, - Keystroke::parse("a", keyboard_mapper.as_ref().as_ref()).unwrap(), + Keystroke::parse("a", keyboard_mapper.as_ref()).unwrap(), ); cx.dispatch_keystroke( *window, - Keystroke::parse("ctrl-g", keyboard_mapper.as_ref().as_ref()).unwrap(), + Keystroke::parse("ctrl-g", keyboard_mapper.as_ref()).unwrap(), ); window diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 1bb0109045..ba6a7b0456 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -236,7 +236,7 @@ pub(crate) trait Platform: 'static { fn read_credentials(&self, url: &str) -> Task)>>>; fn delete_credentials(&self, url: &str) -> Task>; - fn keyboard_mapper(&self) -> Box; + fn keyboard_mapper(&self) -> Rc; fn keyboard_layout(&self) -> Box; fn on_keyboard_layout_change(&self, callback: Box); } diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs index d51f8f6087..87b7d8c473 100644 --- a/crates/gpui/src/platform/linux/platform.rs +++ b/crates/gpui/src/platform/linux/platform.rs @@ -139,14 +139,14 @@ impl Platform for P { self.with_common(|common| common.text_system.clone()) } - fn keyboard_mapper(&self) -> Box { + fn keyboard_mapper(&self) -> Rc { #[cfg(any(feature = "wayland", feature = "x11"))] { - Box::new(super::LinuxKeyboardMapper::new()) + Rc::new(super::LinuxKeyboardMapper::new()) } #[cfg(not(any(feature = "wayland", feature = "x11")))] { - Box::new(crate::EmptyKeyboardMapper) + Rc::new(crate::EmptyKeyboardMapper) } } diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index 2dd23181d5..3ce3a042c6 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -36,6 +36,7 @@ pub(crate) struct TestPlatform { screen_capture_sources: RefCell>, pub opened_url: RefCell>, pub text_system: Arc, + keyboard_mapper: Rc, #[cfg(target_os = "windows")] bitmap_factory: std::mem::ManuallyDrop, weak: Weak, @@ -93,6 +94,7 @@ impl TestPlatform { }; let text_system = Arc::new(NoopTextSystem); + let keyboard_mapper = Rc::new(TestKeyboardMapper::new()); Rc::new_cyclic(|weak| TestPlatform { background_executor: executor, @@ -110,6 +112,7 @@ impl TestPlatform { #[cfg(target_os = "windows")] bitmap_factory, text_system, + keyboard_mapper, }) } @@ -224,8 +227,8 @@ impl Platform for TestPlatform { self.text_system.clone() } - fn keyboard_mapper(&self) -> Box { - Box::new(TestKeyboardMapper::new()) + fn keyboard_mapper(&self) -> Rc { + self.keyboard_mapper.clone() } fn keyboard_layout(&self) -> Box {