Revert "debugger: Process ANSI color escape codes in console" (#32906)
Reverts zed-industries/zed#32817 Release Notes: - N/A
This commit is contained in:
parent
0cda28f786
commit
2f1d25d7f3
23 changed files with 234 additions and 558 deletions
|
@ -80,7 +80,7 @@ pub trait ToDisplayPoint {
|
|||
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
|
||||
}
|
||||
|
||||
type TextHighlights = TreeMap<TypeId, Vec<(Range<Anchor>, HighlightStyle)>>;
|
||||
type TextHighlights = TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
||||
type InlayHighlights = TreeMap<TypeId, TreeMap<InlayId, (HighlightStyle, InlayHighlight)>>;
|
||||
|
||||
/// Decides how text in a [`MultiBuffer`] should be displayed in a buffer, handling inlay hints,
|
||||
|
@ -474,9 +474,11 @@ impl DisplayMap {
|
|||
pub fn highlight_text(
|
||||
&mut self,
|
||||
type_id: TypeId,
|
||||
ranges: Vec<(Range<Anchor>, HighlightStyle)>,
|
||||
ranges: Vec<Range<Anchor>>,
|
||||
style: HighlightStyle,
|
||||
) {
|
||||
self.text_highlights.insert(type_id, ranges);
|
||||
self.text_highlights
|
||||
.insert(type_id, Arc::new((style, ranges)));
|
||||
}
|
||||
|
||||
pub(crate) fn highlight_inlays(
|
||||
|
@ -498,25 +500,16 @@ impl DisplayMap {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn text_highlights(&self, type_id: TypeId) -> Option<&[(Range<Anchor>, HighlightStyle)]> {
|
||||
self.text_highlights
|
||||
.get(&type_id)
|
||||
.map(|highlights| highlights.as_slice())
|
||||
pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[Range<Anchor>])> {
|
||||
let highlights = self.text_highlights.get(&type_id)?;
|
||||
Some((highlights.0, &highlights.1))
|
||||
}
|
||||
|
||||
pub fn clear_highlights(&mut self, type_id: TypeId) -> bool {
|
||||
let mut cleared = self.text_highlights.remove(&type_id).is_some();
|
||||
cleared |= self.inlay_highlights.remove(&type_id).is_some();
|
||||
cleared
|
||||
}
|
||||
|
||||
pub fn remove_text_highlights(
|
||||
&mut self,
|
||||
type_id: TypeId,
|
||||
) -> Option<Vec<(Range<Anchor>, HighlightStyle)>> {
|
||||
self.text_highlights.remove(&type_id)
|
||||
}
|
||||
|
||||
pub fn set_font(&self, font: Font, font_size: Pixels, cx: &mut Context<Self>) -> bool {
|
||||
self.wrap_map
|
||||
.update(cx, |map, cx| map.set_font_with_size(font, font_size, cx))
|
||||
|
@ -1338,7 +1331,7 @@ impl DisplaySnapshot {
|
|||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn text_highlight_ranges<Tag: ?Sized + 'static>(
|
||||
&self,
|
||||
) -> Option<Vec<(Range<Anchor>, HighlightStyle)>> {
|
||||
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
||||
let type_id = TypeId::of::<Tag>();
|
||||
self.text_highlights.get(&type_id).cloned()
|
||||
}
|
||||
|
@ -2303,17 +2296,12 @@ pub mod tests {
|
|||
map.highlight_text(
|
||||
TypeId::of::<usize>(),
|
||||
vec![
|
||||
(
|
||||
buffer_snapshot.anchor_before(Point::new(3, 9))
|
||||
..buffer_snapshot.anchor_after(Point::new(3, 14)),
|
||||
red.into(),
|
||||
),
|
||||
(
|
||||
buffer_snapshot.anchor_before(Point::new(3, 17))
|
||||
..buffer_snapshot.anchor_after(Point::new(3, 18)),
|
||||
red.into(),
|
||||
),
|
||||
buffer_snapshot.anchor_before(Point::new(3, 9))
|
||||
..buffer_snapshot.anchor_after(Point::new(3, 14)),
|
||||
buffer_snapshot.anchor_before(Point::new(3, 17))
|
||||
..buffer_snapshot.anchor_after(Point::new(3, 18)),
|
||||
],
|
||||
red.into(),
|
||||
);
|
||||
map.insert_blocks(
|
||||
[BlockProperties {
|
||||
|
@ -2632,13 +2620,11 @@ pub mod tests {
|
|||
highlighted_ranges
|
||||
.into_iter()
|
||||
.map(|range| {
|
||||
(
|
||||
buffer_snapshot.anchor_before(range.start)
|
||||
..buffer_snapshot.anchor_before(range.end),
|
||||
style,
|
||||
)
|
||||
buffer_snapshot.anchor_before(range.start)
|
||||
..buffer_snapshot.anchor_before(range.end)
|
||||
})
|
||||
.collect(),
|
||||
style,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
use collections::BTreeMap;
|
||||
use gpui::HighlightStyle;
|
||||
use language::Chunk;
|
||||
use multi_buffer::{MultiBufferChunks, MultiBufferSnapshot, ToOffset as _};
|
||||
use multi_buffer::{Anchor, MultiBufferChunks, MultiBufferSnapshot, ToOffset as _};
|
||||
use std::{
|
||||
any::TypeId,
|
||||
cmp,
|
||||
iter::{self, Peekable},
|
||||
ops::Range,
|
||||
sync::Arc,
|
||||
vec,
|
||||
};
|
||||
|
||||
use crate::display_map::TextHighlights;
|
||||
use sum_tree::TreeMap;
|
||||
|
||||
pub struct CustomHighlightsChunks<'a> {
|
||||
buffer_chunks: MultiBufferChunks<'a>,
|
||||
|
@ -19,15 +19,15 @@ pub struct CustomHighlightsChunks<'a> {
|
|||
multibuffer_snapshot: &'a MultiBufferSnapshot,
|
||||
|
||||
highlight_endpoints: Peekable<vec::IntoIter<HighlightEndpoint>>,
|
||||
active_highlights: BTreeMap<(TypeId, usize), HighlightStyle>,
|
||||
text_highlights: Option<&'a TextHighlights>,
|
||||
active_highlights: BTreeMap<TypeId, HighlightStyle>,
|
||||
text_highlights: Option<&'a TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
struct HighlightEndpoint {
|
||||
offset: usize,
|
||||
is_start: bool,
|
||||
tag: (TypeId, usize),
|
||||
tag: TypeId,
|
||||
style: HighlightStyle,
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ impl<'a> CustomHighlightsChunks<'a> {
|
|||
pub fn new(
|
||||
range: Range<usize>,
|
||||
language_aware: bool,
|
||||
text_highlights: Option<&'a TextHighlights>,
|
||||
text_highlights: Option<&'a TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>>,
|
||||
multibuffer_snapshot: &'a MultiBufferSnapshot,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -66,7 +66,7 @@ impl<'a> CustomHighlightsChunks<'a> {
|
|||
|
||||
fn create_highlight_endpoints(
|
||||
range: &Range<usize>,
|
||||
text_highlights: Option<&TextHighlights>,
|
||||
text_highlights: Option<&TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>>,
|
||||
buffer: &MultiBufferSnapshot,
|
||||
) -> iter::Peekable<vec::IntoIter<HighlightEndpoint>> {
|
||||
let mut highlight_endpoints = Vec::new();
|
||||
|
@ -74,7 +74,10 @@ fn create_highlight_endpoints(
|
|||
let start = buffer.anchor_after(range.start);
|
||||
let end = buffer.anchor_after(range.end);
|
||||
for (&tag, text_highlights) in text_highlights.iter() {
|
||||
let start_ix = match text_highlights.binary_search_by(|(probe, _)| {
|
||||
let style = text_highlights.0;
|
||||
let ranges = &text_highlights.1;
|
||||
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&start, &buffer);
|
||||
if cmp.is_gt() {
|
||||
cmp::Ordering::Greater
|
||||
|
@ -85,7 +88,7 @@ fn create_highlight_endpoints(
|
|||
Ok(i) | Err(i) => i,
|
||||
};
|
||||
|
||||
for (ix, (range, style)) in text_highlights[start_ix..].iter().enumerate() {
|
||||
for range in &ranges[start_ix..] {
|
||||
if range.start.cmp(&end, &buffer).is_ge() {
|
||||
break;
|
||||
}
|
||||
|
@ -93,14 +96,14 @@ fn create_highlight_endpoints(
|
|||
highlight_endpoints.push(HighlightEndpoint {
|
||||
offset: range.start.to_offset(&buffer),
|
||||
is_start: true,
|
||||
tag: (tag, ix),
|
||||
style: *style,
|
||||
tag,
|
||||
style,
|
||||
});
|
||||
highlight_endpoints.push(HighlightEndpoint {
|
||||
offset: range.end.to_offset(&buffer),
|
||||
is_start: false,
|
||||
tag: (tag, ix),
|
||||
style: *style,
|
||||
tag,
|
||||
style,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1122,7 +1122,7 @@ mod tests {
|
|||
use project::{InlayHint, InlayHintLabel, ResolveState};
|
||||
use rand::prelude::*;
|
||||
use settings::SettingsStore;
|
||||
use std::{any::TypeId, cmp::Reverse, env};
|
||||
use std::{any::TypeId, cmp::Reverse, env, sync::Arc};
|
||||
use sum_tree::TreeMap;
|
||||
use text::Patch;
|
||||
use util::post_inc;
|
||||
|
@ -1630,16 +1630,16 @@ mod tests {
|
|||
log::info!("highlighting text ranges {text_highlight_ranges:?}");
|
||||
text_highlights.insert(
|
||||
TypeId::of::<()>(),
|
||||
text_highlight_ranges
|
||||
.into_iter()
|
||||
.map(|range| {
|
||||
(
|
||||
Arc::new((
|
||||
HighlightStyle::default(),
|
||||
text_highlight_ranges
|
||||
.into_iter()
|
||||
.map(|range| {
|
||||
buffer_snapshot.anchor_before(range.start)
|
||||
..buffer_snapshot.anchor_after(range.end),
|
||||
HighlightStyle::default(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
..buffer_snapshot.anchor_after(range.end)
|
||||
})
|
||||
.collect(),
|
||||
)),
|
||||
);
|
||||
|
||||
let mut inlay_highlights = InlayHighlights::default();
|
||||
|
|
|
@ -197,7 +197,7 @@ pub use sum_tree::Bias;
|
|||
use sum_tree::TreeMap;
|
||||
use text::{BufferId, FromAnchor, OffsetUtf16, Rope};
|
||||
use theme::{
|
||||
ActiveTheme, PlayerColor, StatusColors, SyntaxTheme, Theme, ThemeSettings,
|
||||
ActiveTheme, PlayerColor, StatusColors, SyntaxTheme, ThemeColors, ThemeSettings,
|
||||
observe_buffer_font_size_adjustment,
|
||||
};
|
||||
use ui::{
|
||||
|
@ -708,12 +708,7 @@ impl EditorActionId {
|
|||
// type GetFieldEditorTheme = dyn Fn(&theme::Theme) -> theme::FieldEditor;
|
||||
// type OverrideTextStyle = dyn Fn(&EditorStyle) -> Option<HighlightStyle>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BackgroundHighlight {
|
||||
pub range: Range<Anchor>,
|
||||
pub color_fetcher: fn(&Theme) -> Hsla,
|
||||
}
|
||||
|
||||
type BackgroundHighlight = (fn(&ThemeColors) -> Hsla, Arc<[Range<Anchor>]>);
|
||||
type GutterHighlight = (fn(&App) -> Hsla, Vec<Range<Anchor>>);
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -1022,7 +1017,7 @@ pub struct Editor {
|
|||
placeholder_text: Option<Arc<str>>,
|
||||
highlight_order: usize,
|
||||
highlighted_rows: HashMap<TypeId, Vec<RowHighlight>>,
|
||||
background_highlights: TreeMap<TypeId, Vec<BackgroundHighlight>>,
|
||||
background_highlights: TreeMap<TypeId, BackgroundHighlight>,
|
||||
gutter_highlights: TreeMap<TypeId, GutterHighlight>,
|
||||
scrollbar_marker_state: ScrollbarMarkerState,
|
||||
active_indent_guides_state: ActiveIndentGuidesState,
|
||||
|
@ -6185,7 +6180,7 @@ impl Editor {
|
|||
editor.update(cx, |editor, cx| {
|
||||
editor.highlight_background::<Self>(
|
||||
&ranges_to_highlight,
|
||||
|theme| theme.colors().editor_highlighted_line_background,
|
||||
|theme| theme.editor_highlighted_line_background,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
@ -6540,12 +6535,12 @@ impl Editor {
|
|||
|
||||
this.highlight_background::<DocumentHighlightRead>(
|
||||
&read_ranges,
|
||||
|theme| theme.colors().editor_document_highlight_read_background,
|
||||
|theme| theme.editor_document_highlight_read_background,
|
||||
cx,
|
||||
);
|
||||
this.highlight_background::<DocumentHighlightWrite>(
|
||||
&write_ranges,
|
||||
|theme| theme.colors().editor_document_highlight_write_background,
|
||||
|theme| theme.editor_document_highlight_write_background,
|
||||
cx,
|
||||
);
|
||||
cx.notify();
|
||||
|
@ -6647,7 +6642,7 @@ impl Editor {
|
|||
if !match_ranges.is_empty() {
|
||||
editor.highlight_background::<SelectedTextHighlight>(
|
||||
&match_ranges,
|
||||
|theme| theme.colors().editor_document_highlight_bracket_background,
|
||||
|theme| theme.editor_document_highlight_bracket_background,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
@ -7523,15 +7518,12 @@ impl Editor {
|
|||
self.splice_inlays(&[], inlays, cx);
|
||||
} else {
|
||||
let background_color = cx.theme().status().deleted_background;
|
||||
let style = HighlightStyle {
|
||||
background_color: Some(background_color),
|
||||
..Default::default()
|
||||
};
|
||||
self.highlight_text::<InlineCompletionHighlight>(
|
||||
edits
|
||||
.iter()
|
||||
.map(|(range, _)| (range.clone(), style))
|
||||
.collect(),
|
||||
edits.iter().map(|(range, _)| range.clone()).collect(),
|
||||
HighlightStyle {
|
||||
background_color: Some(background_color),
|
||||
..Default::default()
|
||||
},
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
@ -15405,7 +15397,7 @@ impl Editor {
|
|||
}
|
||||
editor.highlight_background::<Self>(
|
||||
&ranges,
|
||||
|theme| theme.colors().editor_highlighted_line_background,
|
||||
|theme| theme.editor_highlighted_line_background,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
@ -15560,28 +15552,25 @@ impl Editor {
|
|||
})
|
||||
.detach();
|
||||
|
||||
let write_highlights = this
|
||||
.clear_background_highlights::<DocumentHighlightWrite>(cx)
|
||||
.unwrap_or_default();
|
||||
let read_highlights = this
|
||||
.clear_background_highlights::<DocumentHighlightRead>(cx)
|
||||
.unwrap_or_default();
|
||||
let write_highlights =
|
||||
this.clear_background_highlights::<DocumentHighlightWrite>(cx);
|
||||
let read_highlights =
|
||||
this.clear_background_highlights::<DocumentHighlightRead>(cx);
|
||||
let ranges = write_highlights
|
||||
.iter()
|
||||
.chain(read_highlights.iter())
|
||||
.flat_map(|(_, ranges)| ranges.iter())
|
||||
.chain(read_highlights.iter().flat_map(|(_, ranges)| ranges.iter()))
|
||||
.cloned()
|
||||
.map(|highlight| {
|
||||
(
|
||||
highlight.range,
|
||||
HighlightStyle {
|
||||
fade_out: Some(0.6),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
this.highlight_text::<Rename>(ranges, cx);
|
||||
this.highlight_text::<Rename>(
|
||||
ranges,
|
||||
HighlightStyle {
|
||||
fade_out: Some(0.6),
|
||||
..Default::default()
|
||||
},
|
||||
cx,
|
||||
);
|
||||
let rename_focus_handle = rename_editor.focus_handle(cx);
|
||||
window.focus(&rename_focus_handle);
|
||||
let block_id = this.insert_blocks(
|
||||
|
@ -18563,7 +18552,7 @@ impl Editor {
|
|||
pub fn set_search_within_ranges(&mut self, ranges: &[Range<Anchor>], cx: &mut Context<Self>) {
|
||||
self.highlight_background::<SearchWithinRange>(
|
||||
ranges,
|
||||
|theme| theme.colors().editor_document_highlight_read_background,
|
||||
|colors| colors.editor_document_highlight_read_background,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
@ -18579,29 +18568,11 @@ impl Editor {
|
|||
pub fn highlight_background<T: 'static>(
|
||||
&mut self,
|
||||
ranges: &[Range<Anchor>],
|
||||
color_fetcher: fn(&Theme) -> Hsla,
|
||||
color_fetcher: fn(&ThemeColors) -> Hsla,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let highlights = ranges
|
||||
.iter()
|
||||
.map(|range| BackgroundHighlight {
|
||||
range: range.clone(),
|
||||
color_fetcher,
|
||||
})
|
||||
.collect();
|
||||
self.background_highlights
|
||||
.insert(TypeId::of::<T>(), highlights);
|
||||
self.scrollbar_marker_state.dirty = true;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn highlight_background_ranges<T: 'static>(
|
||||
&mut self,
|
||||
background_highlights: Vec<BackgroundHighlight>,
|
||||
cx: &mut Context<'_, Editor>,
|
||||
) {
|
||||
self.background_highlights
|
||||
.insert(TypeId::of::<T>(), background_highlights);
|
||||
.insert(TypeId::of::<T>(), (color_fetcher, Arc::from(ranges)));
|
||||
self.scrollbar_marker_state.dirty = true;
|
||||
cx.notify();
|
||||
}
|
||||
|
@ -18609,9 +18580,9 @@ impl Editor {
|
|||
pub fn clear_background_highlights<T: 'static>(
|
||||
&mut self,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<Vec<BackgroundHighlight>> {
|
||||
) -> Option<BackgroundHighlight> {
|
||||
let text_highlights = self.background_highlights.remove(&TypeId::of::<T>())?;
|
||||
if !text_highlights.is_empty() {
|
||||
if !text_highlights.1.is_empty() {
|
||||
self.scrollbar_marker_state.dirty = true;
|
||||
cx.notify();
|
||||
}
|
||||
|
@ -18706,7 +18677,7 @@ impl Editor {
|
|||
let buffer = &snapshot.buffer_snapshot;
|
||||
let start = buffer.anchor_before(0);
|
||||
let end = buffer.anchor_after(buffer.len());
|
||||
let theme = cx.theme();
|
||||
let theme = cx.theme().colors();
|
||||
self.background_highlights_in_range(start..end, &snapshot, theme)
|
||||
}
|
||||
|
||||
|
@ -18718,13 +18689,10 @@ impl Editor {
|
|||
.background_highlights
|
||||
.get(&TypeId::of::<items::BufferSearchHighlights>());
|
||||
|
||||
if let Some(highlights) = highlights {
|
||||
highlights
|
||||
if let Some((_color, ranges)) = highlights {
|
||||
ranges
|
||||
.iter()
|
||||
.map(|highlight| {
|
||||
highlight.range.start.to_point(&snapshot)
|
||||
..highlight.range.end.to_point(&snapshot)
|
||||
})
|
||||
.map(|range| range.start.to_point(&snapshot)..range.end.to_point(&snapshot))
|
||||
.collect_vec()
|
||||
} else {
|
||||
vec![]
|
||||
|
@ -18738,18 +18706,20 @@ impl Editor {
|
|||
) -> impl 'a + Iterator<Item = &'a Range<Anchor>> {
|
||||
let read_highlights = self
|
||||
.background_highlights
|
||||
.get(&TypeId::of::<DocumentHighlightRead>());
|
||||
.get(&TypeId::of::<DocumentHighlightRead>())
|
||||
.map(|h| &h.1);
|
||||
let write_highlights = self
|
||||
.background_highlights
|
||||
.get(&TypeId::of::<DocumentHighlightWrite>());
|
||||
.get(&TypeId::of::<DocumentHighlightWrite>())
|
||||
.map(|h| &h.1);
|
||||
let left_position = position.bias_left(buffer);
|
||||
let right_position = position.bias_right(buffer);
|
||||
read_highlights
|
||||
.into_iter()
|
||||
.chain(write_highlights)
|
||||
.flat_map(move |highlights| {
|
||||
let start_ix = match highlights.binary_search_by(|probe| {
|
||||
let cmp = probe.range.end.cmp(&left_position, buffer);
|
||||
.flat_map(move |ranges| {
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe.end.cmp(&left_position, buffer);
|
||||
if cmp.is_ge() {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
|
@ -18759,32 +18729,29 @@ impl Editor {
|
|||
Ok(i) | Err(i) => i,
|
||||
};
|
||||
|
||||
highlights[start_ix..]
|
||||
ranges[start_ix..]
|
||||
.iter()
|
||||
.take_while(move |highlight| {
|
||||
highlight.range.start.cmp(&right_position, buffer).is_le()
|
||||
})
|
||||
.map(|highlight| &highlight.range)
|
||||
.take_while(move |range| range.start.cmp(&right_position, buffer).is_le())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has_background_highlights<T: 'static>(&self) -> bool {
|
||||
self.background_highlights
|
||||
.get(&TypeId::of::<T>())
|
||||
.map_or(false, |highlights| !highlights.is_empty())
|
||||
.map_or(false, |(_, highlights)| !highlights.is_empty())
|
||||
}
|
||||
|
||||
pub fn background_highlights_in_range(
|
||||
&self,
|
||||
search_range: Range<Anchor>,
|
||||
display_snapshot: &DisplaySnapshot,
|
||||
theme: &Theme,
|
||||
theme: &ThemeColors,
|
||||
) -> Vec<(Range<DisplayPoint>, Hsla)> {
|
||||
let mut results = Vec::new();
|
||||
for highlights in self.background_highlights.values() {
|
||||
let start_ix = match highlights.binary_search_by(|probe| {
|
||||
for (color_fetcher, ranges) in self.background_highlights.values() {
|
||||
let color = color_fetcher(theme);
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe
|
||||
.range
|
||||
.end
|
||||
.cmp(&search_range.start, &display_snapshot.buffer_snapshot);
|
||||
if cmp.is_gt() {
|
||||
|
@ -18795,9 +18762,8 @@ impl Editor {
|
|||
}) {
|
||||
Ok(i) | Err(i) => i,
|
||||
};
|
||||
for highlight in &highlights[start_ix..] {
|
||||
if highlight
|
||||
.range
|
||||
for range in &ranges[start_ix..] {
|
||||
if range
|
||||
.start
|
||||
.cmp(&search_range.end, &display_snapshot.buffer_snapshot)
|
||||
.is_ge()
|
||||
|
@ -18805,9 +18771,8 @@ impl Editor {
|
|||
break;
|
||||
}
|
||||
|
||||
let start = highlight.range.start.to_display_point(display_snapshot);
|
||||
let end = highlight.range.end.to_display_point(display_snapshot);
|
||||
let color = (highlight.color_fetcher)(theme);
|
||||
let start = range.start.to_display_point(display_snapshot);
|
||||
let end = range.end.to_display_point(display_snapshot);
|
||||
results.push((start..end, color))
|
||||
}
|
||||
}
|
||||
|
@ -18821,13 +18786,12 @@ impl Editor {
|
|||
count: usize,
|
||||
) -> Vec<RangeInclusive<DisplayPoint>> {
|
||||
let mut results = Vec::new();
|
||||
let Some(highlights) = self.background_highlights.get(&TypeId::of::<T>()) else {
|
||||
let Some((_, ranges)) = self.background_highlights.get(&TypeId::of::<T>()) else {
|
||||
return vec![];
|
||||
};
|
||||
|
||||
let start_ix = match highlights.binary_search_by(|probe| {
|
||||
let start_ix = match ranges.binary_search_by(|probe| {
|
||||
let cmp = probe
|
||||
.range
|
||||
.end
|
||||
.cmp(&search_range.start, &display_snapshot.buffer_snapshot);
|
||||
if cmp.is_gt() {
|
||||
|
@ -18848,31 +18812,24 @@ impl Editor {
|
|||
};
|
||||
let mut start_row: Option<Point> = None;
|
||||
let mut end_row: Option<Point> = None;
|
||||
if highlights.len() > count {
|
||||
if ranges.len() > count {
|
||||
return Vec::new();
|
||||
}
|
||||
for highlight in &highlights[start_ix..] {
|
||||
if highlight
|
||||
.range
|
||||
for range in &ranges[start_ix..] {
|
||||
if range
|
||||
.start
|
||||
.cmp(&search_range.end, &display_snapshot.buffer_snapshot)
|
||||
.is_ge()
|
||||
{
|
||||
break;
|
||||
}
|
||||
let end = highlight
|
||||
.range
|
||||
.end
|
||||
.to_point(&display_snapshot.buffer_snapshot);
|
||||
let end = range.end.to_point(&display_snapshot.buffer_snapshot);
|
||||
if let Some(current_row) = &end_row {
|
||||
if end.row == current_row.row {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let start = highlight
|
||||
.range
|
||||
.start
|
||||
.to_point(&display_snapshot.buffer_snapshot);
|
||||
let start = range.start.to_point(&display_snapshot.buffer_snapshot);
|
||||
if start_row.is_none() {
|
||||
assert_eq!(end_row, None);
|
||||
start_row = Some(start);
|
||||
|
@ -18968,11 +18925,13 @@ impl Editor {
|
|||
|
||||
pub fn highlight_text<T: 'static>(
|
||||
&mut self,
|
||||
ranges: Vec<(Range<Anchor>, HighlightStyle)>,
|
||||
ranges: Vec<Range<Anchor>>,
|
||||
style: HighlightStyle,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.display_map
|
||||
.update(cx, |map, _| map.highlight_text(TypeId::of::<T>(), ranges));
|
||||
self.display_map.update(cx, |map, _| {
|
||||
map.highlight_text(TypeId::of::<T>(), ranges, style)
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
@ -18991,7 +18950,7 @@ impl Editor {
|
|||
pub fn text_highlights<'a, T: 'static>(
|
||||
&'a self,
|
||||
cx: &'a App,
|
||||
) -> Option<&'a [(Range<Anchor>, HighlightStyle)]> {
|
||||
) -> Option<(HighlightStyle, &'a [Range<Anchor>])> {
|
||||
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
||||
}
|
||||
|
||||
|
@ -19004,14 +18963,6 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remove_text_highlights<T: 'static>(
|
||||
&mut self,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<Vec<(Range<Anchor>, HighlightStyle)>> {
|
||||
self.display_map
|
||||
.update(cx, |map, _| map.remove_text_highlights(TypeId::of::<T>()))
|
||||
}
|
||||
|
||||
pub fn show_local_cursors(&self, window: &mut Window, cx: &mut App) -> bool {
|
||||
(self.read_only(cx) || self.blink_manager.read(cx).visible())
|
||||
&& self.focus_handle.is_focused(window)
|
||||
|
@ -19682,11 +19633,11 @@ impl Editor {
|
|||
|
||||
fn marked_text_ranges(&self, cx: &App) -> Option<Vec<Range<OffsetUtf16>>> {
|
||||
let snapshot = self.buffer.read(cx).read(cx);
|
||||
let ranges = self.text_highlights::<InputComposition>(cx)?;
|
||||
let (_, ranges) = self.text_highlights::<InputComposition>(cx)?;
|
||||
Some(
|
||||
ranges
|
||||
.iter()
|
||||
.map(move |(range, _)| {
|
||||
.map(move |range| {
|
||||
range.start.to_offset_utf16(&snapshot)..range.end.to_offset_utf16(&snapshot)
|
||||
})
|
||||
.collect(),
|
||||
|
@ -19997,12 +19948,9 @@ impl Editor {
|
|||
pending = "".to_string();
|
||||
}
|
||||
|
||||
let existing_pending = self.text_highlights::<PendingInput>(cx).map(|ranges| {
|
||||
ranges
|
||||
.iter()
|
||||
.map(|(range, _)| range.clone())
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
let existing_pending = self
|
||||
.text_highlights::<PendingInput>(cx)
|
||||
.map(|(_, ranges)| ranges.iter().cloned().collect::<Vec<_>>());
|
||||
if existing_pending.is_none() && pending.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
@ -20030,27 +19978,28 @@ impl Editor {
|
|||
.all::<usize>(cx)
|
||||
.into_iter()
|
||||
.map(|selection| {
|
||||
(
|
||||
snapshot.buffer_snapshot.anchor_after(selection.end)
|
||||
..snapshot
|
||||
.buffer_snapshot
|
||||
.anchor_before(selection.end + pending.len()),
|
||||
HighlightStyle {
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: None,
|
||||
wavy: false,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
snapshot.buffer_snapshot.anchor_after(selection.end)
|
||||
..snapshot
|
||||
.buffer_snapshot
|
||||
.anchor_before(selection.end + pending.len())
|
||||
})
|
||||
.collect();
|
||||
|
||||
if pending.is_empty() {
|
||||
self.clear_highlights::<PendingInput>(cx);
|
||||
} else {
|
||||
self.highlight_text::<PendingInput>(ranges, cx);
|
||||
self.highlight_text::<PendingInput>(
|
||||
ranges,
|
||||
HighlightStyle {
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: None,
|
||||
wavy: false,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
self.ime_transaction = self.ime_transaction.or(transaction);
|
||||
|
@ -22050,7 +21999,7 @@ impl EntityInputHandler for Editor {
|
|||
|
||||
fn marked_text_range(&self, _: &mut Window, cx: &mut Context<Self>) -> Option<Range<usize>> {
|
||||
let snapshot = self.buffer.read(cx).read(cx);
|
||||
let (range, _) = self.text_highlights::<InputComposition>(cx)?.first()?;
|
||||
let range = self.text_highlights::<InputComposition>(cx)?.1.first()?;
|
||||
Some(range.start.to_offset_utf16(&snapshot).0..range.end.to_offset_utf16(&snapshot).0)
|
||||
}
|
||||
|
||||
|
@ -22187,18 +22136,7 @@ impl EntityInputHandler for Editor {
|
|||
.disjoint_anchors()
|
||||
.iter()
|
||||
.map(|selection| {
|
||||
(
|
||||
selection.start.bias_left(&snapshot)
|
||||
..selection.end.bias_right(&snapshot),
|
||||
HighlightStyle {
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: None,
|
||||
wavy: false,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
selection.start.bias_left(&snapshot)..selection.end.bias_right(&snapshot)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
@ -22206,7 +22144,18 @@ impl EntityInputHandler for Editor {
|
|||
if text.is_empty() {
|
||||
this.unmark_text(window, cx);
|
||||
} else {
|
||||
this.highlight_text::<InputComposition>(marked_ranges.clone(), cx);
|
||||
this.highlight_text::<InputComposition>(
|
||||
marked_ranges.clone(),
|
||||
HighlightStyle {
|
||||
underline: Some(UnderlineStyle {
|
||||
thickness: px(1.),
|
||||
color: None,
|
||||
wavy: false,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
// Disable auto-closing when composing text (i.e. typing a `"` on a Brazilian keyboard)
|
||||
|
@ -22222,7 +22171,7 @@ impl EntityInputHandler for Editor {
|
|||
let snapshot = this.buffer.read(cx).read(cx);
|
||||
let new_selected_ranges = marked_ranges
|
||||
.into_iter()
|
||||
.map(|(marked_range, _)| {
|
||||
.map(|marked_range| {
|
||||
let insertion_start = marked_range.start.to_offset_utf16(&snapshot).0;
|
||||
let new_start = OffsetUtf16(new_selected_range.start + insertion_start);
|
||||
let new_end = OffsetUtf16(new_selected_range.end + insertion_start);
|
||||
|
|
|
@ -13697,7 +13697,7 @@ fn test_highlighted_ranges(cx: &mut TestAppContext) {
|
|||
let mut highlighted_ranges = editor.background_highlights_in_range(
|
||||
anchor_range(Point::new(3, 4)..Point::new(7, 4)),
|
||||
&snapshot,
|
||||
cx.theme(),
|
||||
cx.theme().colors(),
|
||||
);
|
||||
// Enforce a consistent ordering based on color without relying on the ordering of the
|
||||
// highlight's `TypeId` which is non-executor.
|
||||
|
@ -13727,7 +13727,7 @@ fn test_highlighted_ranges(cx: &mut TestAppContext) {
|
|||
editor.background_highlights_in_range(
|
||||
anchor_range(Point::new(5, 6)..Point::new(6, 4)),
|
||||
&snapshot,
|
||||
cx.theme(),
|
||||
cx.theme().colors(),
|
||||
),
|
||||
&[(
|
||||
DisplayPoint::new(DisplayRow(6), 3)..DisplayPoint::new(DisplayRow(6), 5),
|
||||
|
@ -19392,10 +19392,8 @@ async fn test_folding_buffer_when_multibuffer_has_only_one_excerpt(cx: &mut Test
|
|||
let multi_buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
|
||||
let highlight_range = selection_range.clone().to_anchors(&multi_buffer_snapshot);
|
||||
editor.highlight_text::<TestHighlight>(
|
||||
vec![(
|
||||
highlight_range.clone(),
|
||||
HighlightStyle::color(Hsla::green()),
|
||||
)],
|
||||
vec![highlight_range.clone()],
|
||||
HighlightStyle::color(Hsla::green()),
|
||||
cx,
|
||||
);
|
||||
editor.change_selections(None, window, cx, |s| s.select_ranges(Some(highlight_range)));
|
||||
|
@ -20336,7 +20334,7 @@ async fn test_rename_with_duplicate_edits(cx: &mut TestAppContext) {
|
|||
let highlight_range = highlight_range.to_anchors(&editor.buffer().read(cx).snapshot(cx));
|
||||
editor.highlight_background::<DocumentHighlightRead>(
|
||||
&[highlight_range],
|
||||
|c| c.colors().editor_document_highlight_read_background,
|
||||
|c| c.editor_document_highlight_read_background,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
@ -20414,7 +20412,7 @@ async fn test_rename_without_prepare(cx: &mut TestAppContext) {
|
|||
let highlight_range = highlight_range.to_anchors(&editor.buffer().read(cx).snapshot(cx));
|
||||
editor.highlight_background::<DocumentHighlightRead>(
|
||||
&[highlight_range],
|
||||
|c| c.colors().editor_document_highlight_read_background,
|
||||
|c| c.editor_document_highlight_read_background,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -6162,7 +6162,7 @@ impl EditorElement {
|
|||
);
|
||||
}
|
||||
|
||||
for (background_highlight_id, background_highlights) in
|
||||
for (background_highlight_id, (_, background_ranges)) in
|
||||
background_highlights.iter()
|
||||
{
|
||||
let is_search_highlights = *background_highlight_id
|
||||
|
@ -6181,22 +6181,18 @@ impl EditorElement {
|
|||
if is_symbol_occurrences {
|
||||
color.fade_out(0.5);
|
||||
}
|
||||
let marker_row_ranges =
|
||||
background_highlights.iter().map(|highlight| {
|
||||
let display_start = highlight
|
||||
.range
|
||||
.start
|
||||
.to_display_point(&snapshot.display_snapshot);
|
||||
let display_end = highlight
|
||||
.range
|
||||
.end
|
||||
.to_display_point(&snapshot.display_snapshot);
|
||||
ColoredRange {
|
||||
start: display_start.row(),
|
||||
end: display_end.row(),
|
||||
color,
|
||||
}
|
||||
});
|
||||
let marker_row_ranges = background_ranges.iter().map(|range| {
|
||||
let display_start = range
|
||||
.start
|
||||
.to_display_point(&snapshot.display_snapshot);
|
||||
let display_end =
|
||||
range.end.to_display_point(&snapshot.display_snapshot);
|
||||
ColoredRange {
|
||||
start: display_start.row(),
|
||||
end: display_end.row(),
|
||||
color,
|
||||
}
|
||||
});
|
||||
marker_quads.extend(
|
||||
scrollbar_layout
|
||||
.marker_quads_for_ranges(marker_row_ranges, Some(1)),
|
||||
|
@ -8095,7 +8091,7 @@ impl Element for EditorElement {
|
|||
editor.read(cx).background_highlights_in_range(
|
||||
start_anchor..end_anchor,
|
||||
&snapshot.display_snapshot,
|
||||
cx.theme(),
|
||||
cx.theme().colors(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
|
|
@ -40,7 +40,7 @@ pub fn refresh_matching_bracket_highlights(
|
|||
opening_range.to_anchors(&snapshot.buffer_snapshot),
|
||||
closing_range.to_anchors(&snapshot.buffer_snapshot),
|
||||
],
|
||||
|theme| theme.colors().editor_document_highlight_bracket_background,
|
||||
|theme| theme.editor_document_highlight_bracket_background,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -635,7 +635,7 @@ pub fn show_link_definition(
|
|||
|
||||
match highlight_range {
|
||||
RangeInEditor::Text(text_range) => editor
|
||||
.highlight_text::<HoveredLinkState>(vec![(text_range, style)], cx),
|
||||
.highlight_text::<HoveredLinkState>(vec![text_range], style, cx),
|
||||
RangeInEditor::Inlay(highlight) => editor
|
||||
.highlight_inlays::<HoveredLinkState>(vec![highlight], style, cx),
|
||||
}
|
||||
|
@ -1403,6 +1403,7 @@ mod tests {
|
|||
let snapshot = editor.snapshot(window, cx);
|
||||
let actual_ranges = snapshot
|
||||
.text_highlight_ranges::<HoveredLinkState>()
|
||||
.map(|ranges| ranges.as_ref().clone().1)
|
||||
.unwrap_or_default();
|
||||
|
||||
assert!(actual_ranges.is_empty(), "When no cmd is pressed, should have no hint label selected, but got: {actual_ranges:?}");
|
||||
|
@ -1634,6 +1635,7 @@ mod tests {
|
|||
.snapshot(window, cx)
|
||||
.text_highlight_ranges::<HoveredLinkState>()
|
||||
.unwrap_or_default()
|
||||
.1
|
||||
.is_empty()
|
||||
);
|
||||
});
|
||||
|
@ -1840,6 +1842,7 @@ mod tests {
|
|||
.snapshot(window, cx)
|
||||
.text_highlight_ranges::<HoveredLinkState>()
|
||||
.unwrap_or_default()
|
||||
.1
|
||||
.is_empty()
|
||||
);
|
||||
});
|
||||
|
|
|
@ -520,7 +520,7 @@ fn show_hover(
|
|||
// Highlight the selected symbol using a background highlight
|
||||
editor.highlight_background::<HoverState>(
|
||||
&hover_highlights,
|
||||
|theme| theme.colors().element_hover, // todo update theme
|
||||
|theme| theme.element_hover, // todo update theme
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1432,11 +1432,8 @@ impl SearchableItem for Editor {
|
|||
fn get_matches(&self, _window: &mut Window, _: &mut App) -> Vec<Range<Anchor>> {
|
||||
self.background_highlights
|
||||
.get(&TypeId::of::<BufferSearchHighlights>())
|
||||
.map_or(Vec::new(), |highlights| {
|
||||
highlights
|
||||
.iter()
|
||||
.map(|highlight| highlight.range.clone())
|
||||
.collect()
|
||||
.map_or(Vec::new(), |(_color, ranges)| {
|
||||
ranges.iter().cloned().collect()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1455,14 +1452,14 @@ impl SearchableItem for Editor {
|
|||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let existing_ranges = self
|
||||
let existing_range = self
|
||||
.background_highlights
|
||||
.get(&TypeId::of::<BufferSearchHighlights>())
|
||||
.map(|highlights| highlights.iter().map(|highlight| &highlight.range));
|
||||
let updated = !existing_ranges.is_some_and(|existing_ranges| existing_ranges.eq(matches));
|
||||
.map(|(_, range)| range.as_ref());
|
||||
let updated = existing_range != Some(matches);
|
||||
self.highlight_background::<BufferSearchHighlights>(
|
||||
matches,
|
||||
|theme| theme.colors().search_match_background,
|
||||
|theme| theme.search_match_background,
|
||||
cx,
|
||||
);
|
||||
if updated {
|
||||
|
@ -1483,12 +1480,7 @@ impl SearchableItem for Editor {
|
|||
if self.has_filtered_search_ranges() {
|
||||
self.previous_search_ranges = self
|
||||
.clear_background_highlights::<SearchWithinRange>(cx)
|
||||
.map(|highlights| {
|
||||
highlights
|
||||
.iter()
|
||||
.map(|highlight| highlight.range.clone())
|
||||
.collect()
|
||||
})
|
||||
.map(|(_, ranges)| ranges)
|
||||
}
|
||||
|
||||
if !enabled {
|
||||
|
@ -1710,11 +1702,8 @@ impl SearchableItem for Editor {
|
|||
let search_within_ranges = self
|
||||
.background_highlights
|
||||
.get(&TypeId::of::<SearchWithinRange>())
|
||||
.map_or(vec![], |highlights| {
|
||||
highlights
|
||||
.iter()
|
||||
.map(|highlight| highlight.range.clone())
|
||||
.collect::<Vec<_>>()
|
||||
.map_or(vec![], |(_color, ranges)| {
|
||||
ranges.iter().cloned().collect::<Vec<_>>()
|
||||
});
|
||||
|
||||
cx.background_spawn(async move {
|
||||
|
|
|
@ -510,9 +510,10 @@ impl EditorTestContext {
|
|||
editor
|
||||
.background_highlights
|
||||
.get(&TypeId::of::<Tag>())
|
||||
.into_iter()
|
||||
.flat_map(|highlights| highlights.as_slice())
|
||||
.map(|highlight| highlight.range.to_offset(&snapshot.buffer_snapshot))
|
||||
.map(|h| h.1.clone())
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.map(|range| range.to_offset(&snapshot.buffer_snapshot))
|
||||
.collect()
|
||||
});
|
||||
assert_set_eq!(actual_ranges, expected_ranges);
|
||||
|
@ -524,12 +525,7 @@ impl EditorTestContext {
|
|||
let snapshot = self.update_editor(|editor, window, cx| editor.snapshot(window, cx));
|
||||
let actual_ranges: Vec<Range<usize>> = snapshot
|
||||
.text_highlight_ranges::<Tag>()
|
||||
.map(|ranges| {
|
||||
ranges
|
||||
.iter()
|
||||
.map(|(range, _)| range.clone())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.map(|ranges| ranges.as_ref().clone().1)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|range| range.to_offset(&snapshot.buffer_snapshot))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue