Fix incorrect text style in outline palette, use background highlights for matches
This commit is contained in:
parent
da3ba35d1c
commit
84aaeb4360
1 changed files with 37 additions and 12 deletions
|
@ -5,18 +5,20 @@ use editor::{
|
||||||
use fuzzy::StringMatch;
|
use fuzzy::StringMatch;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, rems, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView,
|
actions, div, rems, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView,
|
||||||
FontWeight, ParentElement, Point, Render, Styled, StyledText, Task, TextStyle, View,
|
FontStyle, FontWeight, HighlightStyle, ParentElement, Point, Render, Styled, StyledText, Task,
|
||||||
ViewContext, VisualContext, WeakView, WindowContext,
|
TextStyle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
|
||||||
};
|
};
|
||||||
use language::Outline;
|
use language::Outline;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
|
use settings::Settings;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::{self, Reverse},
|
cmp::{self, Reverse},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use theme::ActiveTheme;
|
|
||||||
use ui::{v_stack, ListItem, Selectable};
|
use theme::{color_alpha, ActiveTheme, ThemeSettings};
|
||||||
|
use ui::{prelude::*, ListItem};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
@ -253,24 +255,47 @@ impl PickerDelegate for OutlineViewDelegate {
|
||||||
&self,
|
&self,
|
||||||
ix: usize,
|
ix: usize,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
_: &mut ViewContext<Picker<Self>>,
|
cx: &mut ViewContext<Picker<Self>>,
|
||||||
) -> Option<Self::ListItem> {
|
) -> 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,
|
||||||
|
font_size: settings.buffer_font_size(cx).into(),
|
||||||
|
font_weight: FontWeight::NORMAL,
|
||||||
|
font_style: FontStyle::Normal,
|
||||||
|
line_height: relative(1.).into(),
|
||||||
|
background_color: None,
|
||||||
|
underline: None,
|
||||||
|
white_space: WhiteSpace::Normal,
|
||||||
|
};
|
||||||
|
|
||||||
|
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 mat = &self.matches[ix];
|
||||||
let outline_item = &self.outline.items[mat.candidate_id];
|
let outline_item = &self.outline.items[mat.candidate_id];
|
||||||
|
|
||||||
let highlights = gpui::combine_highlights(
|
let highlights = gpui::combine_highlights(
|
||||||
mat.ranges().map(|range| (range, FontWeight::BOLD.into())),
|
mat.ranges().map(|range| (range, highlight_style)),
|
||||||
outline_item.highlight_ranges.iter().cloned(),
|
outline_item.highlight_ranges.iter().cloned(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let styled_text = StyledText::new(outline_item.text.clone())
|
let styled_text =
|
||||||
.with_highlights(&TextStyle::default(), highlights);
|
StyledText::new(outline_item.text.clone()).with_highlights(&text_style, highlights);
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
ListItem::new(ix)
|
ListItem::new(ix).inset(true).selected(selected).child(
|
||||||
.inset(true)
|
div()
|
||||||
.selected(selected)
|
.text_ui()
|
||||||
.child(div().pl(rems(outline_item.depth as f32)).child(styled_text)),
|
.pl(rems(outline_item.depth as f32))
|
||||||
|
.child(styled_text),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue