Improve deactivate simulation
This commit is contained in:
parent
319bfff14e
commit
fff415e3e9
5 changed files with 35 additions and 44 deletions
|
@ -930,10 +930,7 @@ mod tests {
|
||||||
fn do_work() { «test»(); }
|
fn do_work() { «test»(); }
|
||||||
"});
|
"});
|
||||||
|
|
||||||
// Deactivating the window dismisses the highlight
|
cx.cx.cx.deactivate_window();
|
||||||
cx.update_workspace(|workspace, cx| {
|
|
||||||
workspace.on_window_activation_changed(cx);
|
|
||||||
});
|
|
||||||
cx.assert_editor_text_highlights::<LinkGoToDefinitionState>(indoc! {"
|
cx.assert_editor_text_highlights::<LinkGoToDefinitionState>(indoc! {"
|
||||||
fn test() { do_work(); }
|
fn test() { do_work(); }
|
||||||
fn do_work() { test(); }
|
fn do_work() { test(); }
|
||||||
|
|
|
@ -519,16 +519,11 @@ impl<'a> VisualTestContext<'a> {
|
||||||
self.cx.simulate_input(self.window, input)
|
self.cx.simulate_input(self.window, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simulate_activation(&mut self) {
|
pub fn deactivate_window(&mut self) {
|
||||||
self.cx
|
if Some(self.window) == self.test_platform.active_window() {
|
||||||
.test_window(self.window)
|
self.test_platform.set_active_window(None)
|
||||||
.simulate_active_status_change(true)
|
|
||||||
}
|
}
|
||||||
|
self.background_executor.run_until_parked();
|
||||||
pub fn simulate_deactivation(&mut self) {
|
|
||||||
self.cx
|
|
||||||
.test_window(self.window)
|
|
||||||
.simulate_active_status_change(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,28 @@ impl TestPlatform {
|
||||||
self.prompts.borrow_mut().multiple_choice.push_back(tx);
|
self.prompts.borrow_mut().multiple_choice.push_back(tx);
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_active_window(&self, window: Option<TestWindow>) {
|
||||||
|
let executor = self.foreground_executor().clone();
|
||||||
|
let previous_window = self.active_window.borrow_mut().take();
|
||||||
|
*self.active_window.borrow_mut() = window.clone();
|
||||||
|
|
||||||
|
executor
|
||||||
|
.spawn(async move {
|
||||||
|
if let Some(previous_window) = previous_window {
|
||||||
|
if let Some(window) = window.as_ref() {
|
||||||
|
if Arc::ptr_eq(&previous_window.0, &window.0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previous_window.simulate_active_status_change(false);
|
||||||
|
}
|
||||||
|
if let Some(window) = window {
|
||||||
|
window.simulate_active_status_change(true);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo!("implement out what our tests needed in GPUI 1")
|
// todo!("implement out what our tests needed in GPUI 1")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
px, AnyWindowHandle, AtlasKey, AtlasTextureId, AtlasTile, Bounds, InputEvent, KeyDownEvent,
|
px, AnyWindowHandle, AtlasKey, AtlasTextureId, AtlasTile, Bounds, InputEvent, KeyDownEvent,
|
||||||
Keystroke, Pixels, Platform, PlatformAtlas, PlatformDisplay, PlatformInputHandler,
|
Keystroke, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler,
|
||||||
PlatformWindow, Point, Size, TestPlatform, TileId, WindowAppearance, WindowBounds,
|
PlatformWindow, Point, Size, TestPlatform, TileId, WindowAppearance, WindowBounds,
|
||||||
WindowOptions,
|
WindowOptions,
|
||||||
};
|
};
|
||||||
|
@ -76,7 +76,7 @@ impl TestWindow {
|
||||||
self.0.lock().resize_callback = Some(callback);
|
self.0.lock().resize_callback = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simulate_active_status_change(&self, active: bool) {
|
pub(crate) fn simulate_active_status_change(&self, active: bool) {
|
||||||
let mut lock = self.0.lock();
|
let mut lock = self.0.lock();
|
||||||
let Some(mut callback) = lock.active_status_change_callback.take() else {
|
let Some(mut callback) = lock.active_status_change_callback.take() else {
|
||||||
return;
|
return;
|
||||||
|
@ -184,33 +184,12 @@ impl PlatformWindow for TestWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(&self) {
|
fn activate(&self) {
|
||||||
let this = self.clone();
|
self.0
|
||||||
let executor = self
|
|
||||||
.0
|
|
||||||
.lock()
|
.lock()
|
||||||
.platform
|
.platform
|
||||||
.upgrade()
|
.upgrade()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.foreground_executor()
|
.set_active_window(Some(self.clone()))
|
||||||
.clone();
|
|
||||||
|
|
||||||
executor
|
|
||||||
.spawn(async move {
|
|
||||||
let state = this.0.lock();
|
|
||||||
let platform = state.platform.upgrade().unwrap();
|
|
||||||
let previous_window = platform.active_window.borrow_mut().replace(this.clone());
|
|
||||||
drop(state);
|
|
||||||
drop(platform);
|
|
||||||
if let Some(previous_window) = previous_window {
|
|
||||||
if Arc::ptr_eq(&previous_window.0, &this.0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
previous_window.simulate_active_status_change(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.simulate_active_status_change(true);
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_title(&mut self, title: &str) {
|
fn set_title(&mut self, title: &str) {
|
||||||
|
|
|
@ -4763,8 +4763,7 @@ mod tests {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Deactivating the window saves the file.
|
// Deactivating the window saves the file.
|
||||||
cx.simulate_deactivation();
|
cx.deactivate_window();
|
||||||
cx.executor().run_until_parked();
|
|
||||||
item.update(cx, |item, _| assert_eq!(item.save_count, 1));
|
item.update(cx, |item, _| assert_eq!(item.save_count, 1));
|
||||||
|
|
||||||
// Autosave on focus change.
|
// Autosave on focus change.
|
||||||
|
@ -4784,14 +4783,13 @@ mod tests {
|
||||||
item.update(cx, |item, _| assert_eq!(item.save_count, 2));
|
item.update(cx, |item, _| assert_eq!(item.save_count, 2));
|
||||||
|
|
||||||
// Deactivating the window still saves the file.
|
// Deactivating the window still saves the file.
|
||||||
cx.simulate_activation();
|
cx.update(|cx| cx.activate_window());
|
||||||
item.update(cx, |item, cx| {
|
item.update(cx, |item, cx| {
|
||||||
cx.focus_self();
|
cx.focus_self();
|
||||||
item.is_dirty = true;
|
item.is_dirty = true;
|
||||||
});
|
});
|
||||||
cx.simulate_deactivation();
|
cx.deactivate_window();
|
||||||
|
|
||||||
cx.executor().run_until_parked();
|
|
||||||
item.update(cx, |item, _| assert_eq!(item.save_count, 3));
|
item.update(cx, |item, _| assert_eq!(item.save_count, 3));
|
||||||
|
|
||||||
// Autosave after delay.
|
// Autosave after delay.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue