Highlight matches by increasing the font weight
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
a64ba8b687
commit
e538beb920
1 changed files with 14 additions and 25 deletions
|
@ -5,9 +5,8 @@ use editor::{
|
||||||
use fuzzy::StringMatch;
|
use fuzzy::StringMatch;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action,
|
action,
|
||||||
color::Color,
|
|
||||||
elements::*,
|
elements::*,
|
||||||
fonts::HighlightStyle,
|
fonts::{self, HighlightStyle},
|
||||||
geometry::vector::Vector2F,
|
geometry::vector::Vector2F,
|
||||||
keymap::{
|
keymap::{
|
||||||
self,
|
self,
|
||||||
|
@ -376,7 +375,6 @@ impl OutlineView {
|
||||||
style.label.text.clone().into(),
|
style.label.text.clone().into(),
|
||||||
&outline_item.highlight_ranges,
|
&outline_item.highlight_ranges,
|
||||||
&string_match.positions,
|
&string_match.positions,
|
||||||
Color::red(),
|
|
||||||
))
|
))
|
||||||
.contained()
|
.contained()
|
||||||
.with_padding_left(20. * outline_item.depth as f32)
|
.with_padding_left(20. * outline_item.depth as f32)
|
||||||
|
@ -391,16 +389,17 @@ fn combine_syntax_and_fuzzy_match_highlights(
|
||||||
default_style: HighlightStyle,
|
default_style: HighlightStyle,
|
||||||
syntax_ranges: &[(Range<usize>, HighlightStyle)],
|
syntax_ranges: &[(Range<usize>, HighlightStyle)],
|
||||||
match_indices: &[usize],
|
match_indices: &[usize],
|
||||||
match_underline: Color,
|
|
||||||
) -> Vec<(Range<usize>, HighlightStyle)> {
|
) -> Vec<(Range<usize>, HighlightStyle)> {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let mut match_indices = match_indices.iter().copied().peekable();
|
let mut match_indices = match_indices.iter().copied().peekable();
|
||||||
|
|
||||||
for (range, syntax_highlight) in syntax_ranges
|
for (range, mut syntax_highlight) in syntax_ranges
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.chain([(usize::MAX..0, Default::default())])
|
.chain([(usize::MAX..0, Default::default())])
|
||||||
{
|
{
|
||||||
|
syntax_highlight.font_properties.weight(Default::default());
|
||||||
|
|
||||||
// Add highlights for any fuzzy match characters before the next
|
// Add highlights for any fuzzy match characters before the next
|
||||||
// syntax highlight range.
|
// syntax highlight range.
|
||||||
while let Some(&match_index) = match_indices.peek() {
|
while let Some(&match_index) = match_indices.peek() {
|
||||||
|
@ -409,13 +408,9 @@ fn combine_syntax_and_fuzzy_match_highlights(
|
||||||
}
|
}
|
||||||
match_indices.next();
|
match_indices.next();
|
||||||
let end_index = char_ix_after(match_index, text);
|
let end_index = char_ix_after(match_index, text);
|
||||||
result.push((
|
let mut match_style = default_style;
|
||||||
match_index..end_index,
|
match_style.font_properties.weight(fonts::Weight::BOLD);
|
||||||
HighlightStyle {
|
result.push((match_index..end_index, match_style));
|
||||||
underline: Some(match_underline),
|
|
||||||
..default_style
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if range.start == usize::MAX {
|
if range.start == usize::MAX {
|
||||||
|
@ -445,13 +440,9 @@ fn combine_syntax_and_fuzzy_match_highlights(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push((
|
let mut match_style = syntax_highlight;
|
||||||
match_index..end_index,
|
match_style.font_properties.weight(fonts::Weight::BOLD);
|
||||||
HighlightStyle {
|
result.push((match_index..end_index, match_style));
|
||||||
underline: Some(match_underline),
|
|
||||||
..syntax_highlight
|
|
||||||
},
|
|
||||||
));
|
|
||||||
offset = end_index;
|
offset = end_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +461,7 @@ fn char_ix_after(ix: usize, text: &str) -> usize {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use gpui::fonts::HighlightStyle;
|
use gpui::{color::Color, fonts::HighlightStyle};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_combine_syntax_and_fuzzy_match_highlights() {
|
fn test_combine_syntax_and_fuzzy_match_highlights() {
|
||||||
|
@ -493,14 +484,12 @@ mod tests {
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
let match_indices = [4, 6, 7, 8];
|
let match_indices = [4, 6, 7, 8];
|
||||||
let match_underline = Color::white();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
combine_syntax_and_fuzzy_match_highlights(
|
combine_syntax_and_fuzzy_match_highlights(
|
||||||
&string,
|
&string,
|
||||||
default,
|
default,
|
||||||
&syntax_ranges,
|
&syntax_ranges,
|
||||||
&match_indices,
|
&match_indices,
|
||||||
match_underline
|
|
||||||
),
|
),
|
||||||
&[
|
&[
|
||||||
(
|
(
|
||||||
|
@ -514,7 +503,7 @@ mod tests {
|
||||||
4..5,
|
4..5,
|
||||||
HighlightStyle {
|
HighlightStyle {
|
||||||
color: Color::green(),
|
color: Color::green(),
|
||||||
underline: Some(match_underline),
|
font_properties: *fonts::Properties::default().weight(fonts::Weight::BOLD),
|
||||||
..default
|
..default
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -529,14 +518,14 @@ mod tests {
|
||||||
6..8,
|
6..8,
|
||||||
HighlightStyle {
|
HighlightStyle {
|
||||||
color: Color::green(),
|
color: Color::green(),
|
||||||
underline: Some(match_underline),
|
font_properties: *fonts::Properties::default().weight(fonts::Weight::BOLD),
|
||||||
..default
|
..default
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
8..9,
|
8..9,
|
||||||
HighlightStyle {
|
HighlightStyle {
|
||||||
underline: Some(match_underline),
|
font_properties: *fonts::Properties::default().weight(fonts::Weight::BOLD),
|
||||||
..default
|
..default
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue