mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-09 00:50:04 +03:00
💄
This commit is contained in:
parent
84b05d6c05
commit
3bb29acd26
@ -70,18 +70,35 @@ impl DispatchTree {
|
||||
self.keystroke_matchers.clear();
|
||||
}
|
||||
|
||||
pub fn push_node(&mut self, context: Option<KeyContext>) {
|
||||
pub fn push_node(
|
||||
&mut self,
|
||||
context: Option<KeyContext>,
|
||||
focus_id: Option<FocusId>,
|
||||
view_id: Option<EntityId>,
|
||||
) {
|
||||
let parent = self.node_stack.last().copied();
|
||||
let node_id = DispatchNodeId(self.nodes.len());
|
||||
self.nodes.push(DispatchNode {
|
||||
parent,
|
||||
focus_id,
|
||||
view_id,
|
||||
..Default::default()
|
||||
});
|
||||
self.node_stack.push(node_id);
|
||||
|
||||
if let Some(context) = context {
|
||||
self.active_node().context = Some(context.clone());
|
||||
self.context_stack.push(context);
|
||||
}
|
||||
|
||||
if let Some(focus_id) = focus_id {
|
||||
self.focusable_node_ids.insert(focus_id, node_id);
|
||||
}
|
||||
|
||||
if let Some(view_id) = view_id {
|
||||
self.view_stack.push(view_id);
|
||||
self.view_node_ids.insert(view_id, node_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pop_node(&mut self) {
|
||||
@ -96,14 +113,11 @@ impl DispatchTree {
|
||||
}
|
||||
|
||||
fn move_node(&mut self, source_node: &mut DispatchNode) {
|
||||
self.push_node(source_node.context.take());
|
||||
if let Some(focus_id) = source_node.focus_id {
|
||||
self.make_focusable(focus_id);
|
||||
}
|
||||
if let Some(view_id) = source_node.view_id {
|
||||
self.associate_view(view_id);
|
||||
}
|
||||
|
||||
self.push_node(
|
||||
source_node.context.take(),
|
||||
source_node.focus_id,
|
||||
source_node.view_id,
|
||||
);
|
||||
let target_node = self.active_node();
|
||||
target_node.key_listeners = mem::take(&mut source_node.key_listeners);
|
||||
target_node.action_listeners = mem::take(&mut source_node.action_listeners);
|
||||
@ -195,19 +209,6 @@ impl DispatchTree {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn make_focusable(&mut self, focus_id: FocusId) {
|
||||
let node_id = self.active_node_id();
|
||||
self.active_node().focus_id = Some(focus_id);
|
||||
self.focusable_node_ids.insert(focus_id, node_id);
|
||||
}
|
||||
|
||||
pub fn associate_view(&mut self, view_id: EntityId) {
|
||||
let node_id = self.active_node_id();
|
||||
self.active_node().view_id = Some(view_id);
|
||||
self.view_node_ids.insert(view_id, node_id);
|
||||
self.view_stack.push(view_id);
|
||||
}
|
||||
|
||||
pub fn focus_contains(&self, parent: FocusId, child: FocusId) -> bool {
|
||||
if parent == child {
|
||||
return true;
|
||||
|
@ -1866,13 +1866,12 @@ impl<'a> WindowContext<'a> {
|
||||
f: impl FnOnce(Option<FocusHandle>, &mut Self) -> R,
|
||||
) -> R {
|
||||
let window = &mut self.window;
|
||||
window.next_frame.dispatch_tree.push_node(context.clone());
|
||||
if let Some(focus_handle) = focus_handle.as_ref() {
|
||||
window
|
||||
.next_frame
|
||||
.dispatch_tree
|
||||
.make_focusable(focus_handle.id);
|
||||
}
|
||||
let focus_id = focus_handle.as_ref().map(|handle| handle.id);
|
||||
window
|
||||
.next_frame
|
||||
.dispatch_tree
|
||||
.push_node(context.clone(), focus_id, None);
|
||||
|
||||
let result = f(focus_handle, self);
|
||||
|
||||
self.window.next_frame.dispatch_tree.pop_node();
|
||||
@ -2165,11 +2164,10 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {
|
||||
}
|
||||
|
||||
fn with_view_id<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
|
||||
self.window_mut().next_frame.dispatch_tree.push_node(None);
|
||||
self.window_mut()
|
||||
.next_frame
|
||||
.dispatch_tree
|
||||
.associate_view(view_id);
|
||||
.push_node(None, None, Some(view_id));
|
||||
let result = f(self);
|
||||
self.window_mut().next_frame.dispatch_tree.pop_node();
|
||||
result
|
||||
|
Loading…
Reference in New Issue
Block a user