Make channel notes view searchable and navigable via pane history

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-08-24 17:18:18 -07:00
parent 7b6c0c539c
commit a95dcfa8bc
4 changed files with 46 additions and 13 deletions

View file

@ -10,13 +10,17 @@ use editor::Editor;
use gpui::{ use gpui::{
actions, actions,
elements::{ChildView, Label}, elements::{ChildView, Label},
geometry::vector::Vector2F,
AnyElement, AnyViewHandle, AppContext, Element, Entity, ModelHandle, Subscription, Task, View, AnyElement, AnyViewHandle, AppContext, Element, Entity, ModelHandle, Subscription, Task, View,
ViewContext, ViewHandle, ViewContext, ViewHandle,
}; };
use project::Project; use project::Project;
use std::any::Any;
use workspace::{ use workspace::{
item::{FollowableItem, Item, ItemHandle}, item::{FollowableItem, Item, ItemHandle},
register_followable_item, Pane, ViewId, Workspace, WorkspaceId, register_followable_item,
searchable::SearchableItemHandle,
ItemNavHistory, Pane, ViewId, Workspace, WorkspaceId,
}; };
actions!(channel_view, [Deploy]); actions!(channel_view, [Deploy]);
@ -207,6 +211,37 @@ impl Item for ChannelView {
cx, cx,
)) ))
} }
fn is_singleton(&self, _cx: &AppContext) -> bool {
true
}
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) -> bool {
self.editor
.update(cx, |editor, cx| editor.navigate(data, cx))
}
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
self.editor
.update(cx, |editor, cx| Item::deactivated(editor, cx))
}
fn set_nav_history(&mut self, history: ItemNavHistory, cx: &mut ViewContext<Self>) {
self.editor
.update(cx, |editor, cx| Item::set_nav_history(editor, history, cx))
}
fn as_searchable(&self, _: &ViewHandle<Self>) -> Option<Box<dyn SearchableItemHandle>> {
Some(Box::new(self.editor.clone()))
}
fn show_toolbar(&self) -> bool {
true
}
fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> {
self.editor.read(cx).pixel_position_of_cursor(cx)
}
} }
impl FollowableItem for ChannelView { impl FollowableItem for ChannelView {

View file

@ -754,7 +754,7 @@ impl Item for Editor {
Some(Box::new(handle.clone())) Some(Box::new(handle.clone()))
} }
fn pixel_position_of_cursor(&self) -> Option<Vector2F> { fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Vector2F> {
self.pixel_position_of_newest_cursor self.pixel_position_of_newest_cursor
} }

View file

@ -391,7 +391,7 @@ mod test {
the lazy dog" the lazy dog"
}) })
.await; .await;
let cursor = cx.update_editor(|editor, _| editor.pixel_position_of_cursor()); let cursor = cx.update_editor(|editor, cx| editor.pixel_position_of_cursor(cx));
// entering visual mode should select the character // entering visual mode should select the character
// under cursor // under cursor
@ -400,7 +400,7 @@ mod test {
fox jumps over fox jumps over
the lazy dog"}) the lazy dog"})
.await; .await;
cx.update_editor(|editor, _| assert_eq!(cursor, editor.pixel_position_of_cursor())); cx.update_editor(|editor, cx| assert_eq!(cursor, editor.pixel_position_of_cursor(cx)));
// forwards motions should extend the selection // forwards motions should extend the selection
cx.simulate_shared_keystrokes(["w", "j"]).await; cx.simulate_shared_keystrokes(["w", "j"]).await;
@ -430,7 +430,7 @@ mod test {
b b
"}) "})
.await; .await;
let cursor = cx.update_editor(|editor, _| editor.pixel_position_of_cursor()); let cursor = cx.update_editor(|editor, cx| editor.pixel_position_of_cursor(cx));
cx.simulate_shared_keystrokes(["v"]).await; cx.simulate_shared_keystrokes(["v"]).await;
cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
a a
@ -438,7 +438,7 @@ mod test {
ˇ»b ˇ»b
"}) "})
.await; .await;
cx.update_editor(|editor, _| assert_eq!(cursor, editor.pixel_position_of_cursor())); cx.update_editor(|editor, cx| assert_eq!(cursor, editor.pixel_position_of_cursor(cx)));
// toggles off again // toggles off again
cx.simulate_shared_keystrokes(["v"]).await; cx.simulate_shared_keystrokes(["v"]).await;
@ -510,7 +510,7 @@ mod test {
b b
ˇ"}) ˇ"})
.await; .await;
let cursor = cx.update_editor(|editor, _| editor.pixel_position_of_cursor()); let cursor = cx.update_editor(|editor, cx| editor.pixel_position_of_cursor(cx));
cx.simulate_shared_keystrokes(["shift-v"]).await; cx.simulate_shared_keystrokes(["shift-v"]).await;
cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
a a
@ -518,7 +518,7 @@ mod test {
ˇ"}) ˇ"})
.await; .await;
assert_eq!(cx.mode(), cx.neovim_mode().await); assert_eq!(cx.mode(), cx.neovim_mode().await);
cx.update_editor(|editor, _| assert_eq!(cursor, editor.pixel_position_of_cursor())); cx.update_editor(|editor, cx| assert_eq!(cursor, editor.pixel_position_of_cursor(cx)));
cx.simulate_shared_keystrokes(["x"]).await; cx.simulate_shared_keystrokes(["x"]).await;
cx.assert_shared_state(indoc! {" cx.assert_shared_state(indoc! {"
a a

View file

@ -158,9 +158,7 @@ pub trait Item: View {
fn should_update_tab_on_event(_: &Self::Event) -> bool { fn should_update_tab_on_event(_: &Self::Event) -> bool {
false false
} }
fn is_edit_event(_: &Self::Event) -> bool {
false
}
fn act_as_type<'a>( fn act_as_type<'a>(
&'a self, &'a self,
type_id: TypeId, type_id: TypeId,
@ -205,7 +203,7 @@ pub trait Item: View {
fn show_toolbar(&self) -> bool { fn show_toolbar(&self) -> bool {
true true
} }
fn pixel_position_of_cursor(&self) -> Option<Vector2F> { fn pixel_position_of_cursor(&self, _: &AppContext) -> Option<Vector2F> {
None None
} }
} }
@ -623,7 +621,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
} }
fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> { fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> {
self.read(cx).pixel_position_of_cursor() self.read(cx).pixel_position_of_cursor(cx)
} }
} }