fix: Sync sidebar selection on click
Update sidebar click handlers to set the keyboard selection and scroll position so mouse actions stay in sync with the highlight.
This commit is contained in:
+22
-4
@@ -78,10 +78,14 @@ impl Sidebar {
|
|||||||
fn handle_project_click(
|
fn handle_project_click(
|
||||||
&mut self,
|
&mut self,
|
||||||
full_path: Option<String>,
|
full_path: Option<String>,
|
||||||
|
selected_index: Option<usize>,
|
||||||
_window: &mut Window,
|
_window: &mut Window,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
cx.emit(SidebarEvent::Focused(SidebarSection::Projects));
|
cx.emit(SidebarEvent::Focused(SidebarSection::Projects));
|
||||||
|
self.selected_section = SidebarSection::Projects;
|
||||||
|
self.selected_index = selected_index;
|
||||||
|
self.scroll_to_selected();
|
||||||
self.filter_state.update(cx, |filter, cx| {
|
self.filter_state.update(cx, |filter, cx| {
|
||||||
filter.select_project(full_path);
|
filter.select_project(full_path);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
@@ -95,8 +99,17 @@ impl Sidebar {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_tag_click(&mut self, tag_name: String, _window: &mut Window, cx: &mut Context<Self>) {
|
fn handle_tag_click(
|
||||||
|
&mut self,
|
||||||
|
tag_name: String,
|
||||||
|
selected_index: usize,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
cx.emit(SidebarEvent::Focused(SidebarSection::Tags));
|
cx.emit(SidebarEvent::Focused(SidebarSection::Tags));
|
||||||
|
self.selected_section = SidebarSection::Tags;
|
||||||
|
self.selected_index = Some(selected_index);
|
||||||
|
self.scroll_to_selected();
|
||||||
self.filter_state.update(cx, |filter, cx| {
|
self.filter_state.update(cx, |filter, cx| {
|
||||||
filter.toggle_tag(tag_name);
|
filter.toggle_tag(tag_name);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
@@ -314,7 +327,7 @@ impl Sidebar {
|
|||||||
.on_mouse_down(
|
.on_mouse_down(
|
||||||
gpui::MouseButton::Left,
|
gpui::MouseButton::Left,
|
||||||
cx.listener(|view, _event, window, cx| {
|
cx.listener(|view, _event, window, cx| {
|
||||||
view.handle_project_click(None, window, cx);
|
view.handle_project_click(None, Some(0), window, cx);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -416,7 +429,12 @@ impl Sidebar {
|
|||||||
.on_mouse_down(
|
.on_mouse_down(
|
||||||
gpui::MouseButton::Left,
|
gpui::MouseButton::Left,
|
||||||
cx.listener(move |view, _event, window, cx| {
|
cx.listener(move |view, _event, window, cx| {
|
||||||
view.handle_project_click(Some(full_path.clone()), window, cx);
|
view.handle_project_click(
|
||||||
|
Some(full_path.clone()),
|
||||||
|
Some(idx + 1),
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -475,7 +493,7 @@ impl Sidebar {
|
|||||||
.on_mouse_down(
|
.on_mouse_down(
|
||||||
gpui::MouseButton::Left,
|
gpui::MouseButton::Left,
|
||||||
cx.listener(move |view, _event, window, cx| {
|
cx.listener(move |view, _event, window, cx| {
|
||||||
view.handle_tag_click(tag_name.clone(), window, cx);
|
view.handle_tag_click(tag_name.clone(), idx, window, cx);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
Reference in New Issue
Block a user