Add a way to filter items in the outline panel (#13984)
https://github.com/zed-industries/zed/assets/2690773/145a7cf2-332c-46c9-ab2f-42a77504f54f Adds a way to filter entries in the outline panel, by showing all entries (even if their parents were collapsed) that fuzzy match a given query. Release Notes: - Added a way to filter items in the outline panel
This commit is contained in:
parent
9a6f30fd95
commit
9b688655a8
7 changed files with 1072 additions and 870 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -7355,6 +7355,7 @@ dependencies = [
|
||||||
"db",
|
"db",
|
||||||
"editor",
|
"editor",
|
||||||
"file_icons",
|
"file_icons",
|
||||||
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
"itertools 0.11.0",
|
"itertools 0.11.0",
|
||||||
"language",
|
"language",
|
||||||
|
|
|
@ -502,6 +502,7 @@
|
||||||
{
|
{
|
||||||
"context": "OutlinePanel",
|
"context": "OutlinePanel",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
"escape": "menu::Cancel",
|
||||||
"left": "outline_panel::CollapseSelectedEntry",
|
"left": "outline_panel::CollapseSelectedEntry",
|
||||||
"right": "outline_panel::ExpandSelectedEntry",
|
"right": "outline_panel::ExpandSelectedEntry",
|
||||||
"ctrl-alt-c": "outline_panel::CopyPath",
|
"ctrl-alt-c": "outline_panel::CopyPath",
|
||||||
|
|
|
@ -523,6 +523,7 @@
|
||||||
{
|
{
|
||||||
"context": "OutlinePanel",
|
"context": "OutlinePanel",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
"escape": "menu::Cancel",
|
||||||
"left": "outline_panel::CollapseSelectedEntry",
|
"left": "outline_panel::CollapseSelectedEntry",
|
||||||
"right": "outline_panel::ExpandSelectedEntry",
|
"right": "outline_panel::ExpandSelectedEntry",
|
||||||
"cmd-alt-c": "outline_panel::CopyPath",
|
"cmd-alt-c": "outline_panel::CopyPath",
|
||||||
|
|
|
@ -5,7 +5,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use theme::{ActiveTheme, ThemeSettings};
|
use theme::{color_alpha, ActiveTheme, ThemeSettings};
|
||||||
|
|
||||||
/// An outline of all the symbols contained in a buffer.
|
/// An outline of all the symbols contained in a buffer.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -146,9 +146,15 @@ impl<T> Outline<T> {
|
||||||
|
|
||||||
pub fn render_item<T>(
|
pub fn render_item<T>(
|
||||||
outline_item: &OutlineItem<T>,
|
outline_item: &OutlineItem<T>,
|
||||||
custom_highlights: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
|
match_ranges: impl IntoIterator<Item = Range<usize>>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> StyledText {
|
) -> StyledText {
|
||||||
|
let mut highlight_style = HighlightStyle::default();
|
||||||
|
highlight_style.background_color = Some(color_alpha(cx.theme().colors().text_accent, 0.3));
|
||||||
|
let custom_highlights = match_ranges
|
||||||
|
.into_iter()
|
||||||
|
.map(|range| (range, highlight_style));
|
||||||
|
|
||||||
let settings = ThemeSettings::get_global(cx);
|
let settings = ThemeSettings::get_global(cx);
|
||||||
|
|
||||||
// TODO: We probably shouldn't need to build a whole new text style here
|
// TODO: We probably shouldn't need to build a whole new text style here
|
||||||
|
|
|
@ -3,9 +3,8 @@ use editor::{
|
||||||
};
|
};
|
||||||
use fuzzy::StringMatch;
|
use fuzzy::StringMatch;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, rems, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, HighlightStyle,
|
div, rems, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, ParentElement,
|
||||||
ParentElement, Point, Render, Styled, Task, View, ViewContext, VisualContext, WeakView,
|
Point, Render, Styled, Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||||
WindowContext,
|
|
||||||
};
|
};
|
||||||
use language::Outline;
|
use language::Outline;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
|
@ -15,7 +14,7 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use theme::{color_alpha, ActiveTheme};
|
use theme::ActiveTheme;
|
||||||
use ui::{prelude::*, ListItem, ListItemSpacing};
|
use ui::{prelude::*, ListItem, ListItemSpacing};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{DismissDecision, ModalView};
|
use workspace::{DismissDecision, ModalView};
|
||||||
|
@ -272,10 +271,6 @@ impl PickerDelegate for OutlineViewDelegate {
|
||||||
let mat = self.matches.get(ix)?;
|
let mat = self.matches.get(ix)?;
|
||||||
let outline_item = self.outline.items.get(mat.candidate_id)?;
|
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 custom_highlights = mat.ranges().map(|range| (range, highlight_style));
|
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
ListItem::new(ix)
|
ListItem::new(ix)
|
||||||
.inset(true)
|
.inset(true)
|
||||||
|
@ -285,7 +280,7 @@ impl PickerDelegate for OutlineViewDelegate {
|
||||||
div()
|
div()
|
||||||
.text_ui(cx)
|
.text_ui(cx)
|
||||||
.pl(rems(outline_item.depth as f32))
|
.pl(rems(outline_item.depth as f32))
|
||||||
.child(language::render_item(outline_item, custom_highlights, cx)),
|
.child(language::render_item(outline_item, mat.ranges(), cx)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ collections.workspace = true
|
||||||
db.workspace = true
|
db.workspace = true
|
||||||
editor.workspace = true
|
editor.workspace = true
|
||||||
file_icons.workspace = true
|
file_icons.workspace = true
|
||||||
|
fuzzy.workspace = true
|
||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
language.workspace = true
|
language.workspace = true
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue