Move debug_elements to AsyncAppContext

Previously, `debug_elements` was available on `WindowContext`. If that
method was called while having a borrow out to a view, it would panic because
the view would already have been borrowed.

By moving it to an `AsyncAppContext` we ensure the method can't be called while
a view is being used.
This commit is contained in:
Antonio Scandurra 2023-05-02 11:03:01 +02:00
parent 4c1cba6def
commit 794446bf8b
4 changed files with 23 additions and 20 deletions

View file

@ -43,6 +43,7 @@ use window_input_handler::WindowInputHandler;
use crate::{
elements::{AnyElement, AnyRootElement, RootElement},
executor::{self, Task},
json,
keymap_matcher::{self, Binding, KeymapContext, KeymapMatcher, Keystroke, MatchResult},
platform::{
self, FontSystem, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, MouseButton,
@ -309,6 +310,14 @@ impl AsyncAppContext {
self.0.borrow_mut().update_window(window_id, callback)
}
pub fn debug_elements(&self, window_id: usize) -> Option<json::Value> {
self.0.borrow().read_window(window_id, |cx| {
let root_view = cx.window.root_view();
let root_element = cx.window.rendered_views.get(&root_view.id())?;
root_element.debug(cx).log_err()
})?
}
pub fn dispatch_action(
&mut self,
window_id: usize,