Merge branch 'main' into copilot

This commit is contained in:
Mikayla Maki 2023-03-29 16:57:38 -07:00
commit ae3b3ea458
20 changed files with 351 additions and 165 deletions

View file

@ -1603,6 +1603,10 @@ impl View for Pane {
}
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.toolbar.update(cx, |toolbar, cx| {
toolbar.pane_focus_update(true, cx);
});
if let Some(active_item) = self.active_item() {
if cx.is_self_focused() {
// Pane was focused directly. We need to either focus a view inside the active item,
@ -1626,6 +1630,12 @@ impl View for Pane {
}
}
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.toolbar.update(cx, |toolbar, cx| {
toolbar.pane_focus_update(false, cx);
});
}
fn keymap_context(&self, _: &AppContext) -> KeymapContext {
let mut keymap = Self::default_keymap_context();
if self.docked.is_some() {

View file

@ -20,6 +20,8 @@ pub trait ToolbarItemView: View {
) -> ToolbarItemLocation {
current_location
}
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut MutableAppContext) {}
}
trait ToolbarItemViewHandle {
@ -30,6 +32,7 @@ trait ToolbarItemViewHandle {
active_pane_item: Option<&dyn ItemHandle>,
cx: &mut MutableAppContext,
) -> ToolbarItemLocation;
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut MutableAppContext);
}
#[derive(Copy, Clone, Debug, PartialEq)]
@ -260,6 +263,12 @@ impl Toolbar {
}
}
pub fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut MutableAppContext) {
for (toolbar_item, _) in self.items.iter_mut() {
toolbar_item.pane_focus_update(pane_focused, cx);
}
}
pub fn item_of_type<T: ToolbarItemView>(&self) -> Option<ViewHandle<T>> {
self.items
.iter()
@ -289,6 +298,10 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
this.set_active_pane_item(active_pane_item, cx)
})
}
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut MutableAppContext) {
self.update(cx, |this, cx| this.pane_focus_update(pane_focused, cx));
}
}
impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle {