Pane focus working. Modals seem broken now
This commit is contained in:
parent
049149320c
commit
6f180ed822
11 changed files with 43 additions and 103 deletions
|
@ -13,9 +13,9 @@ use gpui::{
|
|||
},
|
||||
impl_actions, impl_internal_actions,
|
||||
platform::{CursorStyle, NavigationDirection},
|
||||
AnyViewHandle, AppContext, AsyncAppContext, Entity, EventContext, ModelHandle, MouseButton,
|
||||
MouseButtonEvent, MutableAppContext, PromptLevel, Quad, RenderContext, Task, View, ViewContext,
|
||||
ViewHandle, WeakViewHandle,
|
||||
AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity, EventContext,
|
||||
ModelHandle, MouseButton, MouseButtonEvent, MutableAppContext, PromptLevel, Quad,
|
||||
RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use project::{Project, ProjectEntryId, ProjectPath};
|
||||
use serde::Deserialize;
|
||||
|
@ -132,7 +132,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
}
|
||||
|
||||
pub enum Event {
|
||||
Activate,
|
||||
Focused,
|
||||
ActivateItem { local: bool },
|
||||
Remove,
|
||||
RemoveItem,
|
||||
|
@ -144,6 +144,7 @@ pub struct Pane {
|
|||
items: Vec<Box<dyn ItemHandle>>,
|
||||
is_active: bool,
|
||||
active_item_index: usize,
|
||||
last_focused_view: Option<AnyWeakViewHandle>,
|
||||
autoscroll: bool,
|
||||
nav_history: Rc<RefCell<NavHistory>>,
|
||||
toolbar: ViewHandle<Toolbar>,
|
||||
|
@ -193,6 +194,7 @@ impl Pane {
|
|||
items: Vec::new(),
|
||||
is_active: true,
|
||||
active_item_index: 0,
|
||||
last_focused_view: None,
|
||||
autoscroll: false,
|
||||
nav_history: Rc::new(RefCell::new(NavHistory {
|
||||
mode: NavigationMode::Normal,
|
||||
|
@ -219,10 +221,6 @@ impl Pane {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn activate(&self, cx: &mut ViewContext<Self>) {
|
||||
cx.emit(Event::Activate);
|
||||
}
|
||||
|
||||
pub fn go_back(
|
||||
workspace: &mut Workspace,
|
||||
pane: Option<ViewHandle<Pane>>,
|
||||
|
@ -287,7 +285,7 @@ impl Pane {
|
|||
mode: NavigationMode,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Task<()> {
|
||||
workspace.activate_pane(pane.clone(), cx);
|
||||
cx.focus(pane.clone());
|
||||
|
||||
let to_load = pane.update(cx, |pane, cx| {
|
||||
loop {
|
||||
|
@ -523,7 +521,7 @@ impl Pane {
|
|||
self.focus_active_item(cx);
|
||||
}
|
||||
if activate_pane {
|
||||
self.activate(cx);
|
||||
cx.emit(Event::Focused);
|
||||
}
|
||||
self.autoscroll = true;
|
||||
cx.notify();
|
||||
|
@ -830,7 +828,6 @@ impl Pane {
|
|||
pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(active_item) = self.active_item() {
|
||||
cx.focus(active_item);
|
||||
self.activate(cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1212,11 +1209,20 @@ impl View for Pane {
|
|||
}
|
||||
|
||||
fn on_focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
if cx.handle().id() == focused.id() {
|
||||
self.focus_active_item(cx);
|
||||
if cx.is_self_focused() {
|
||||
if let Some(last_focused_view) = self
|
||||
.last_focused_view
|
||||
.as_ref()
|
||||
.and_then(|handle| handle.upgrade(cx))
|
||||
{
|
||||
cx.focus(last_focused_view);
|
||||
} else {
|
||||
self.focus_active_item(cx);
|
||||
}
|
||||
} else {
|
||||
self.activate(cx);
|
||||
self.last_focused_view = Some(focused.downgrade());
|
||||
}
|
||||
cx.emit(Event::Focused);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue