Introduce an outline panel (#12637)
Adds a new panel: `OutlinePanel` which looks very close to project panel: <img width="256" alt="Screenshot 2024-06-10 at 23 19 05" src="https://github.com/zed-industries/zed/assets/2690773/c66e6e78-44ec-4de8-8d60-43238bb09ae9"> has similar settings and keymap (actions work in the `OutlinePanel` context and are under `outline_panel::` namespace), with two notable differences: * no "edit" actions such as cut/copy/paste/delete/etc. * directory auto folding is enabled by default Empty view: <img width="841" alt="Screenshot 2024-06-10 at 23 19 11" src="https://github.com/zed-industries/zed/assets/2690773/dc8bf37c-5a70-4fd5-9b57-76271eb7a40c"> When editor gets active, the panel displays all related files in a tree (similar to what the project panel does) and all related excerpts' outlines under each file. Same as in the project panel, directories can be expanded or collapsed, unfolded or folded; clicking file entries or outlines scrolls the buffer to the corresponding excerpt; changing editor's selection reveals the corresponding outline in the panel. The panel is applicable to any singleton buffer: <img width="1215" alt="Screenshot 2024-06-10 at 23 19 35" src="https://github.com/zed-industries/zed/assets/2690773/a087631f-5c2d-4d4d-ae25-30ab9731d528"> <img width="1728" alt="image" src="https://github.com/zed-industries/zed/assets/2690773/e4f8082c-d12d-4473-8500-e8fd1051285b"> or any multi buffer: (search multi buffer) <img width="1728" alt="Screenshot 2024-06-10 at 23 19 41" src="https://github.com/zed-industries/zed/assets/2690773/60f768a3-6716-4520-9b13-42da8fd15f50"> (diagnostics multi buffer) <img width="1728" alt="image" src="https://github.com/zed-industries/zed/assets/2690773/64e285bd-9530-4bf2-8f1f-10ee5596067c"> Release Notes: - Added an outline panel to show a "map" of the active editor
This commit is contained in:
parent
7f56f4e78e
commit
8451dba6a7
27 changed files with 2860 additions and 57 deletions
|
@ -19,7 +19,6 @@ gpui.workspace = true
|
|||
language.workspace = true
|
||||
ordered-float.workspace = true
|
||||
picker.workspace = true
|
||||
settings.workspace = true
|
||||
smol.workspace = true
|
||||
theme.workspace = true
|
||||
ui.workspace = true
|
||||
|
|
|
@ -2,19 +2,18 @@ use editor::{scroll::Autoscroll, Anchor, AnchorRangeExt, Editor, EditorMode};
|
|||
use fuzzy::StringMatch;
|
||||
use gpui::{
|
||||
actions, div, rems, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
|
||||
FontStyle, FontWeight, HighlightStyle, ParentElement, Point, Render, Styled, StyledText, Task,
|
||||
TextStyle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
|
||||
HighlightStyle, ParentElement, Point, Render, Styled, Task, View, ViewContext, VisualContext,
|
||||
WeakView, WindowContext,
|
||||
};
|
||||
use language::Outline;
|
||||
use ordered_float::OrderedFloat;
|
||||
use picker::{Picker, PickerDelegate};
|
||||
use settings::Settings;
|
||||
use std::{
|
||||
cmp::{self, Reverse},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use theme::{color_alpha, ActiveTheme, ThemeSettings};
|
||||
use theme::{color_alpha, ActiveTheme};
|
||||
use ui::{prelude::*, ListItem, ListItemSpacing};
|
||||
use util::ResultExt;
|
||||
use workspace::{DismissDecision, ModalView};
|
||||
|
@ -268,38 +267,12 @@ impl PickerDelegate for OutlineViewDelegate {
|
|||
selected: bool,
|
||||
cx: &mut ViewContext<Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
|
||||
// TODO: We probably shouldn't need to build a whole new text style here
|
||||
// but I'm not sure how to get the current one and modify it.
|
||||
// Before this change TextStyle::default() was used here, which was giving us the wrong font and text color.
|
||||
let text_style = TextStyle {
|
||||
color: cx.theme().colors().text,
|
||||
font_family: settings.buffer_font.family.clone(),
|
||||
font_features: settings.buffer_font.features.clone(),
|
||||
font_size: settings.buffer_font_size(cx).into(),
|
||||
font_weight: FontWeight::NORMAL,
|
||||
font_style: FontStyle::Normal,
|
||||
line_height: relative(1.),
|
||||
background_color: None,
|
||||
underline: None,
|
||||
strikethrough: None,
|
||||
white_space: WhiteSpace::Normal,
|
||||
};
|
||||
let mat = self.matches.get(ix)?;
|
||||
let outline_item = self.outline.items.get(mat.candidate_id)?;
|
||||
|
||||
let mut highlight_style = HighlightStyle::default();
|
||||
highlight_style.background_color = Some(color_alpha(cx.theme().colors().text_accent, 0.3));
|
||||
|
||||
let mat = &self.matches[ix];
|
||||
let outline_item = &self.outline.items[mat.candidate_id];
|
||||
|
||||
let highlights = gpui::combine_highlights(
|
||||
mat.ranges().map(|range| (range, highlight_style)),
|
||||
outline_item.highlight_ranges.iter().cloned(),
|
||||
);
|
||||
|
||||
let styled_text =
|
||||
StyledText::new(outline_item.text.clone()).with_highlights(&text_style, highlights);
|
||||
let custom_highlights = mat.ranges().map(|range| (range, highlight_style));
|
||||
|
||||
Some(
|
||||
ListItem::new(ix)
|
||||
|
@ -310,7 +283,7 @@ impl PickerDelegate for OutlineViewDelegate {
|
|||
div()
|
||||
.text_ui(cx)
|
||||
.pl(rems(outline_item.depth as f32))
|
||||
.child(styled_text),
|
||||
.child(language::render_item(outline_item, custom_highlights, cx)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue