Quick and dirty attempt to immediately apply focus change in tests

Doesn't quite work yet
This commit is contained in:
Julia 2023-12-13 21:48:05 -05:00
parent cfc050e3fe
commit cd08d349a5
3 changed files with 22 additions and 5 deletions

View file

@ -571,6 +571,7 @@ impl AppContext {
loop { loop {
self.release_dropped_entities(); self.release_dropped_entities();
self.release_dropped_focus_handles(); self.release_dropped_focus_handles();
if let Some(effect) = self.pending_effects.pop_front() { if let Some(effect) = self.pending_effects.pop_front() {
match effect { match effect {
Effect::Notify { emitter } => { Effect::Notify { emitter } => {
@ -610,7 +611,8 @@ impl AppContext {
.values() .values()
.filter_map(|window| { .filter_map(|window| {
let window = window.as_ref()?; let window = window.as_ref()?;
window.dirty.then_some(window.handle) dbg!(window.focus_invalidated);
(window.dirty || window.focus_invalidated).then_some(window.handle)
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
{ {

View file

@ -243,6 +243,9 @@ pub struct Window {
pub(crate) dirty: bool, pub(crate) dirty: bool,
activation_observers: SubscriberSet<(), AnyObserver>, activation_observers: SubscriberSet<(), AnyObserver>,
pub(crate) focus: Option<FocusId>, pub(crate) focus: Option<FocusId>,
#[cfg(any(test, feature = "test-support"))]
pub(crate) focus_invalidated: bool,
} }
pub(crate) struct ElementStateBox { pub(crate) struct ElementStateBox {
@ -381,6 +384,9 @@ impl Window {
dirty: false, dirty: false,
activation_observers: SubscriberSet::new(), activation_observers: SubscriberSet::new(),
focus: None, focus: None,
#[cfg(any(test, feature = "test-support"))]
focus_invalidated: false,
} }
} }
} }
@ -461,6 +467,12 @@ impl<'a> WindowContext<'a> {
.rendered_frame .rendered_frame
.dispatch_tree .dispatch_tree
.clear_pending_keystrokes(); .clear_pending_keystrokes();
#[cfg(any(test, feature = "test-support"))]
{
self.window.focus_invalidated = true;
}
self.notify(); self.notify();
} }
@ -1274,13 +1286,15 @@ impl<'a> WindowContext<'a> {
self.window.root_view = Some(root_view); self.window.root_view = Some(root_view);
let previous_focus_path = self.window.rendered_frame.focus_path(); let previous_focus_path = self.window.rendered_frame.focus_path();
mem::swap(&mut self.window.rendered_frame, &mut self.window.next_frame);
let window = &mut self.window;
mem::swap(&mut window.rendered_frame, &mut window.next_frame);
let current_focus_path = self.window.rendered_frame.focus_path(); let current_focus_path = self.window.rendered_frame.focus_path();
if previous_focus_path != current_focus_path { if previous_focus_path != current_focus_path {
#[cfg(any(test, feature = "test-support"))]
{
self.window.focus_invalidated = false;
}
if !previous_focus_path.is_empty() && current_focus_path.is_empty() { if !previous_focus_path.is_empty() && current_focus_path.is_empty() {
self.window self.window
.blur_listeners .blur_listeners

View file

@ -739,6 +739,7 @@ impl ProjectPanel {
}); });
self.filename_editor.update(cx, |editor, cx| { self.filename_editor.update(cx, |editor, cx| {
editor.clear(cx); editor.clear(cx);
println!("focusing");
editor.focus(cx); editor.focus(cx);
}); });
self.update_visible_entries(Some((worktree_id, NEW_ENTRY_ID)), cx); self.update_visible_entries(Some((worktree_id, NEW_ENTRY_ID)), cx);