Reimplement AppContext::handle_focus_effect

This commit is contained in:
Antonio Scandurra 2023-04-13 16:21:39 +02:00
parent 4900e04ff3
commit ff774786bf

View file

@ -2108,55 +2108,59 @@ impl AppContext {
}); });
} }
fn handle_focus_effect(&mut self, window_id: usize, focused_id: Option<usize>) { fn handle_focus_effect(&mut self, window_id: usize, mut focused_id: Option<usize>) {
todo!() let mut blurred_id = None;
// if self println!("FOCUS: {:?}", focused_id);
// .windows self.update_window(window_id, |cx| {
// .get(&window_id) println!(
// .map(|w| w.focused_view_id) "INSIDE FOCUS: {:?}. PREVIOUS FOCUS: {:?}",
// .map_or(false, |cur_focused| cur_focused == focused_id) focused_id,
// { cx.focused_view_id()
// return; );
// } if cx.window.focused_view_id == focused_id {
focused_id = None;
return;
}
blurred_id = cx.window.focused_view_id;
cx.window.focused_view_id = focused_id;
// self.update(|this| { let blurred_parents = blurred_id
// let blurred_id = this.windows.get_mut(&window_id).and_then(|window| { .map(|blurred_id| cx.ancestors(window_id, blurred_id).collect::<Vec<_>>())
// let blurred_id = window.focused_view_id; .unwrap_or_default();
// window.focused_view_id = focused_id; let focused_parents = focused_id
// blurred_id .map(|focused_id| cx.ancestors(window_id, focused_id).collect::<Vec<_>>())
// }); .unwrap_or_default();
// let blurred_parents = blurred_id if let Some(blurred_id) = blurred_id {
// .map(|blurred_id| this.ancestors(window_id, blurred_id).collect::<Vec<_>>()) for view_id in blurred_parents.iter().copied() {
// .unwrap_or_default(); if let Some(mut view) = cx.views.remove(&(window_id, view_id)) {
// let focused_parents = focused_id view.focus_out(blurred_id, cx, view_id);
// .map(|focused_id| this.ancestors(window_id, focused_id).collect::<Vec<_>>()) cx.views.insert((window_id, view_id), view);
// .unwrap_or_default(); }
}
}
// if let Some(blurred_id) = blurred_id { if let Some(focused_id) = focused_id {
// for view_id in blurred_parents.iter().copied() { for view_id in focused_parents {
// if let Some(mut view) = this.views.remove(&(window_id, view_id)) { if let Some(mut view) = cx.views.remove(&(window_id, view_id)) {
// view.focus_out(this, window_id, view_id, blurred_id); view.focus_in(focused_id, cx, view_id);
// this.views.insert((window_id, view_id), view); cx.views.insert((window_id, view_id), view);
// } }
// } }
}
});
// let mut subscriptions = this.focus_observations.clone(); self.update(|cx| {
// subscriptions.emit(blurred_id, this, |callback, this| callback(false, this)); if let Some(blurred_id) = blurred_id {
// } let mut subscriptions = cx.focus_observations.clone();
subscriptions.emit(blurred_id, cx, |callback, this| callback(false, this));
}
// if let Some(focused_id) = focused_id { if let Some(focused_id) = focused_id {
// for view_id in focused_parents { let mut subscriptions = cx.focus_observations.clone();
// if let Some(mut view) = this.views.remove(&(window_id, view_id)) { subscriptions.emit(focused_id, cx, |callback, this| callback(true, this));
// view.focus_in(this, window_id, view_id, focused_id); }
// this.views.insert((window_id, view_id), view); });
// }
// }
// let mut subscriptions = this.focus_observations.clone();
// subscriptions.emit(focused_id, this, |callback, this| callback(true, this));
// }
// })
} }
fn handle_dispatch_action_from_effect( fn handle_dispatch_action_from_effect(