Rework entry opening in the OutlinePanel

* If any entry is selected, the corresponding editor will be activated and scrolled to entry's location (focus stays in the OutlinePanel still)
* If any entry is open, the entry will be selected (as described above) and the caret placed at entry's location
This commit is contained in:
Kirill Bulatov 2024-11-07 17:37:58 +02:00
parent 454c9dc06d
commit f685361940
3 changed files with 15 additions and 15 deletions

View File

@ -564,7 +564,7 @@
"ctrl-alt-c": "outline_panel::CopyPath",
"alt-ctrl-shift-c": "outline_panel::CopyRelativePath",
"alt-ctrl-r": "outline_panel::RevealInFileManager",
"space": ["outline_panel::Open", { "change_selection": false }],
"space": "outline_panel::Open",
"shift-down": "menu::SelectNext",
"shift-up": "menu::SelectPrev"
}

View File

@ -577,7 +577,7 @@
"cmd-alt-c": "outline_panel::CopyPath",
"alt-cmd-shift-c": "outline_panel::CopyRelativePath",
"alt-cmd-r": "outline_panel::RevealInFileManager",
"space": ["outline_panel::Open", { "change_selection": false }],
"space": "outline_panel::Open",
"shift-down": "menu::SelectNext",
"shift-up": "menu::SelectPrev"
}

View File

@ -23,9 +23,9 @@ use editor::{
use file_icons::FileIcons;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{
actions, anchored, deferred, div, impl_actions, point, px, size, uniform_list, Action,
AnyElement, AppContext, AssetSource, AsyncWindowContext, Bounds, ClipboardItem, DismissEvent,
Div, ElementId, EventEmitter, FocusHandle, FocusableView, HighlightStyle, InteractiveElement,
actions, anchored, deferred, div, point, px, size, uniform_list, Action, AnyElement,
AppContext, AssetSource, AsyncWindowContext, Bounds, ClipboardItem, DismissEvent, Div,
ElementId, EventEmitter, FocusHandle, FocusableView, HighlightStyle, InteractiveElement,
IntoElement, KeyContext, ListHorizontalSizingBehavior, ListSizingBehavior, Model, MouseButton,
MouseDownEvent, ParentElement, Pixels, Point, Render, ScrollStrategy, SharedString, Stateful,
StatefulInteractiveElement as _, Styled, Subscription, Task, UniformListScrollHandle, View,
@ -58,13 +58,6 @@ use workspace::{
};
use worktree::{Entry, ProjectEntryId, WorktreeId};
#[derive(Clone, Default, Deserialize, PartialEq)]
pub struct Open {
change_selection: bool,
}
impl_actions!(outline_panel, [Open]);
actions!(
outline_panel,
[
@ -75,9 +68,10 @@ actions!(
ExpandAllEntries,
ExpandSelectedEntry,
FoldDirectory,
ToggleActiveEditorPin,
Open,
RevealInFileManager,
SelectParent,
ToggleActiveEditorPin,
ToggleFocus,
UnfoldDirectory,
]
@ -813,11 +807,11 @@ impl OutlinePanel {
self.update_cached_entries(None, cx);
}
fn open(&mut self, open: &Open, cx: &mut ViewContext<Self>) {
fn open(&mut self, _: &Open, cx: &mut ViewContext<Self>) {
if self.filter_editor.focus_handle(cx).is_focused(cx) {
cx.propagate()
} else if let Some(selected_entry) = self.selected_entry().cloned() {
self.open_entry(&selected_entry, open.change_selection, cx);
self.open_entry(&selected_entry, true, cx);
}
}
@ -949,6 +943,9 @@ impl OutlinePanel {
} else {
self.select_first(&SelectFirst {}, cx)
}
if let Some(selected_entry) = self.selected_entry().cloned() {
self.open_entry(&selected_entry, false, cx);
}
}
fn select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
@ -965,6 +962,9 @@ impl OutlinePanel {
} else {
self.select_last(&SelectLast, cx)
}
if let Some(selected_entry) = self.selected_entry().cloned() {
self.open_entry(&selected_entry, false, cx);
}
}
fn select_parent(&mut self, _: &SelectParent, cx: &mut ViewContext<Self>) {