Expose a focus handle from workspace::Item
This commit is contained in:
parent
97d1d9bd9b
commit
6fc7b17259
3 changed files with 18 additions and 8 deletions
|
@ -7,8 +7,8 @@ use anyhow::{anyhow, Context, Result};
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use futures::future::try_join_all;
|
use futures::future::try_join_all;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
point, AnyElement, AppContext, AsyncAppContext, Entity, EntityId, Model, Pixels, SharedString,
|
point, AnyElement, AppContext, AsyncAppContext, Entity, EntityId, FocusHandle, Model, Pixels,
|
||||||
Subscription, Task, View, ViewContext, VisualContext, WeakView,
|
SharedString, Subscription, Task, View, ViewContext, VisualContext, WeakView,
|
||||||
};
|
};
|
||||||
use language::{
|
use language::{
|
||||||
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, OffsetRangeExt, Point,
|
proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, OffsetRangeExt, Point,
|
||||||
|
@ -515,6 +515,10 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item for Editor {
|
impl Item for Editor {
|
||||||
|
fn focus_handle(&self) -> FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||||
todo!();
|
todo!();
|
||||||
// if let Ok(data) = data.downcast::<NavigationData>() {
|
// if let Ok(data) = data.downcast::<NavigationData>() {
|
||||||
|
|
|
@ -12,8 +12,8 @@ use client2::{
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
use gpui2::{
|
use gpui2::{
|
||||||
AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, HighlightStyle, Model, Pixels,
|
AnyElement, AnyView, AppContext, Entity, EntityId, EventEmitter, FocusHandle, HighlightStyle,
|
||||||
Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
|
Model, Pixels, Point, Render, SharedString, Task, View, ViewContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||||
|
@ -91,6 +91,7 @@ pub struct BreadcrumbText {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Item: Render + EventEmitter {
|
pub trait Item: Render + EventEmitter {
|
||||||
|
fn focus_handle(&self) -> FocusHandle;
|
||||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn workspace_deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||||
|
@ -212,6 +213,7 @@ pub trait Item: Render + EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ItemHandle: 'static + Send {
|
pub trait ItemHandle: 'static + Send {
|
||||||
|
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
|
||||||
fn subscribe_to_item_events(
|
fn subscribe_to_item_events(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
|
@ -290,6 +292,10 @@ impl dyn ItemHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Item> ItemHandle for View<T> {
|
impl<T: Item> ItemHandle for View<T> {
|
||||||
|
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle {
|
||||||
|
self.read(cx).focus_handle()
|
||||||
|
}
|
||||||
|
|
||||||
fn subscribe_to_item_events(
|
fn subscribe_to_item_events(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
|
|
|
@ -1185,10 +1185,10 @@ impl Pane {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn focus_active_item(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
todo!();
|
if let Some(active_item) = self.active_item() {
|
||||||
// if let Some(active_item) = self.active_item() {
|
let focus_handle = active_item.focus_handle(cx);
|
||||||
// cx.focus(active_item.as_any());
|
cx.focus(&focus_handle);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext<Self>) {
|
// pub fn split(&mut self, direction: SplitDirection, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue