Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/agent_ui/src/inline_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ impl InlineAssistant {
for row_range in inserted_row_ranges {
editor.highlight_rows::<InlineAssist>(
row_range,
cx.theme().status().info_background,
|cx| cx.theme().status().info_background,
Default::default(),
cx,
);
Expand Down Expand Up @@ -1423,7 +1423,7 @@ impl InlineAssistant {
editor.set_show_edit_predictions(Some(false), window, cx);
editor.highlight_rows::<DeletedLines>(
Anchor::Min..Anchor::Max,
cx.theme().status().deleted_background,
|cx| cx.theme().status().deleted_background,
Default::default(),
cx,
);
Expand Down
40 changes: 20 additions & 20 deletions crates/debugger_ui/src/tests/debugger_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ async fn test_active_debug_line_setting(executor: BackgroundExecutor, cx: &mut T
cx.run_until_parked();

main_editor.update_in(cx, |editor, window, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert_eq!(
active_debug_lines.len(),
Expand All @@ -1616,8 +1616,8 @@ async fn test_active_debug_line_setting(executor: BackgroundExecutor, cx: &mut T
assert_eq!(point.row, 1);
});

second_editor.update(cx, |editor, _| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
second_editor.update(cx, |editor, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert!(
active_debug_lines.is_empty(),
Expand Down Expand Up @@ -1675,7 +1675,7 @@ async fn test_active_debug_line_setting(executor: BackgroundExecutor, cx: &mut T
cx.run_until_parked();

second_editor.update_in(cx, |editor, window, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert_eq!(
active_debug_lines.len(),
Expand All @@ -1691,8 +1691,8 @@ async fn test_active_debug_line_setting(executor: BackgroundExecutor, cx: &mut T
assert_eq!(point.row, 2);
});

main_editor.update(cx, |editor, _| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
main_editor.update(cx, |editor, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert!(
active_debug_lines.is_empty(),
Expand All @@ -1714,17 +1714,17 @@ async fn test_active_debug_line_setting(executor: BackgroundExecutor, cx: &mut T

cx.run_until_parked();

second_editor.update(cx, |editor, _| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
second_editor.update(cx, |editor, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert!(
active_debug_lines.is_empty(),
"There shouldn't be any active debug lines"
);
});

main_editor.update(cx, |editor, _| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
main_editor.update(cx, |editor, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert!(
active_debug_lines.is_empty(),
Expand All @@ -1741,17 +1741,17 @@ async fn test_active_debug_line_setting(executor: BackgroundExecutor, cx: &mut T

shutdown_session.await.unwrap();

main_editor.update(cx, |editor, _| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
main_editor.update(cx, |editor, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert!(
active_debug_lines.is_empty(),
"There shouldn't be any active debug lines after session shutdown"
);
});

second_editor.update(cx, |editor, _| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>().collect();
second_editor.update(cx, |editor, cx| {
let active_debug_lines: Vec<_> = editor.highlighted_rows::<ActiveDebugLine>(cx).collect();

assert!(
active_debug_lines.is_empty(),
Expand Down Expand Up @@ -2076,7 +2076,7 @@ async fn test_breakpoint_jumps_only_in_proper_split_view(
if let Some(editor) = item.to_any_view().downcast::<Editor>().ok() {
total_active_debug_lines += editor
.read(cx)
.highlighted_rows::<ActiveDebugLine>()
.highlighted_rows::<ActiveDebugLine>(cx)
.count();
}
}
Expand All @@ -2096,7 +2096,7 @@ async fn test_breakpoint_jumps_only_in_proper_split_view(

let active_debug_lines: Vec<_> = pane_b_editor
.read(cx)
.highlighted_rows::<ActiveDebugLine>()
.highlighted_rows::<ActiveDebugLine>(cx)
.collect();

assert_eq!(
Expand Down Expand Up @@ -2170,7 +2170,7 @@ async fn test_breakpoint_jumps_only_in_proper_split_view(

let active_debug_lines: Vec<_> = pane_b_editor
.read(cx)
.highlighted_rows::<ActiveDebugLine>()
.highlighted_rows::<ActiveDebugLine>(cx)
.collect();

assert_eq!(
Expand All @@ -2190,7 +2190,7 @@ async fn test_breakpoint_jumps_only_in_proper_split_view(
if let Some(editor) = item.to_any_view().downcast::<Editor>().ok() {
total_active_debug_lines += editor
.read(cx)
.highlighted_rows::<ActiveDebugLine>()
.highlighted_rows::<ActiveDebugLine>(cx)
.count();
}
}
Expand Down Expand Up @@ -2304,7 +2304,7 @@ async fn test_breakpoint_jumps_only_in_proper_split_view(

let active_debug_lines: Vec<_> = pane_c_editor
.read(cx)
.highlighted_rows::<ActiveDebugLine>()
.highlighted_rows::<ActiveDebugLine>(cx)
.collect();

assert_eq!(
Expand All @@ -2324,7 +2324,7 @@ async fn test_breakpoint_jumps_only_in_proper_split_view(
if let Some(editor) = item.to_any_view().downcast::<Editor>().ok() {
total_active_debug_lines += editor
.read(cx)
.highlighted_rows::<ActiveDebugLine>()
.highlighted_rows::<ActiveDebugLine>(cx)
.count();
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/debugger_ui/src/tests/stack_frame_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
let snapshot = editor.snapshot(window, cx);

editor
.highlighted_rows::<editor::ActiveDebugLine>()
.highlighted_rows::<editor::ActiveDebugLine>(cx)
.map(|(range, _)| {
let start = range.start.to_point(&snapshot.buffer_snapshot());
let end = range.end.to_point(&snapshot.buffer_snapshot());
Expand Down Expand Up @@ -408,7 +408,7 @@ async fn test_select_stack_frame(executor: BackgroundExecutor, cx: &mut TestAppC
let snapshot = editor.snapshot(window, cx);

editor
.highlighted_rows::<editor::ActiveDebugLine>()
.highlighted_rows::<editor::ActiveDebugLine>(cx)
.map(|(range, _)| {
let start = range.start.to_point(&snapshot.buffer_snapshot());
let end = range.end.to_point(&snapshot.buffer_snapshot());
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/edit_prediction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl Editor {
));
self.highlight_rows::<EditPredictionPreview>(
target..target,
cx.theme().colors().editor_highlighted_line_background,
|cx| cx.theme().colors().editor_highlighted_line_background,
RowHighlightOptions {
autoscroll: true,
..Default::default()
Expand Down
18 changes: 9 additions & 9 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,6 @@ impl EditorActionId {
}
}

// type GetFieldEditorTheme = dyn Fn(&theme::Theme) -> theme::FieldEditor;
// type OverrideTextStyle = dyn Fn(&EditorStyle) -> Option<HighlightStyle>;

type BackgroundHighlight = (
Arc<dyn Fn(&usize, &Theme) -> Hsla + Send + Sync>,
Arc<[Range<Anchor>]>,
Expand Down Expand Up @@ -1493,7 +1490,7 @@ impl Default for RowHighlightOptions {
struct RowHighlight {
index: usize,
range: Range<Anchor>,
color: Hsla,
color: fn(&App) -> Hsla,
options: RowHighlightOptions,
type_id: TypeId,
}
Expand Down Expand Up @@ -6217,7 +6214,7 @@ impl Editor {

self.go_to_line::<ActiveDebugLine>(
multibuffer_anchor,
Some(cx.theme().colors().editor_debugger_active_line_background),
|cx| cx.theme().colors().editor_debugger_active_line_background,
window,
cx,
);
Expand Down Expand Up @@ -8624,7 +8621,7 @@ impl Editor {
pub fn highlight_rows<T: 'static>(
&mut self,
range: Range<Anchor>,
color: Hsla,
color: fn(&App) -> Hsla,
options: RowHighlightOptions,
cx: &mut Context<Self>,
) {
Expand Down Expand Up @@ -8736,12 +8733,15 @@ impl Editor {
}

/// For a highlight given context type, gets all anchor ranges that will be used for row highlighting.
pub fn highlighted_rows<T: 'static>(&self) -> impl '_ + Iterator<Item = (Range<Anchor>, Hsla)> {
pub fn highlighted_rows<'a, T: 'static>(
&'a self,
cx: &'a App,
) -> impl 'a + Iterator<Item = (Range<Anchor>, Hsla)> {
self.highlighted_rows
.get(&TypeId::of::<T>())
.map_or(&[] as &[_], |vec| vec.as_slice())
.iter()
.map(|highlight| (highlight.range.clone(), highlight.color))
.map(|highlight| (highlight.range.clone(), (highlight.color)(cx)))
}

/// Merges all anchor ranges for all context types ever set, picking the last highlight added in case of a row conflict.
Expand Down Expand Up @@ -8778,7 +8778,7 @@ impl Editor {
LineHighlight {
include_gutter: highlight.options.include_gutter,
border: None,
background: highlight.color.into(),
background: (highlight.color)(cx).into(),
type_id: Some(highlight.type_id),
},
);
Expand Down
10 changes: 2 additions & 8 deletions crates/editor/src/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ impl Editor {
pub(super) fn go_to_line<T: 'static>(
&mut self,
position: Anchor,
highlight_color: Option<Hsla>,
highlight_color: fn(&App) -> Hsla,
window: &mut Window,
cx: &mut Context<Self>,
) {
Expand All @@ -1566,13 +1566,7 @@ impl Editor {
let start = snapshot.buffer_snapshot().anchor_before(start);
let end = snapshot.buffer_snapshot().anchor_before(end);

self.highlight_rows::<T>(
start..end,
highlight_color
.unwrap_or_else(|| cx.theme().colors().editor_highlighted_line_background),
Default::default(),
cx,
);
self.highlight_rows::<T>(start..end, highlight_color, Default::default(), cx);

if self.buffer.read(cx).is_singleton() {
self.request_autoscroll(Autoscroll::center().for_anchor(start), cx);
Expand Down
4 changes: 2 additions & 2 deletions crates/git_ui/src/conflict_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ fn update_conflict_highlighting(
let ours = buffer.buffer_anchor_range_to_anchor_range(conflict.ours.clone())?;
let theirs = buffer.buffer_anchor_range_to_anchor_range(conflict.theirs.clone())?;

let ours_background = cx.theme().colors().version_control_conflict_marker_ours;
let theirs_background = cx.theme().colors().version_control_conflict_marker_theirs;
let ours_background = |cx: &App| cx.theme().colors().version_control_conflict_marker_ours;
let theirs_background = |cx: &App| cx.theme().colors().version_control_conflict_marker_theirs;

let options = RowHighlightOptions {
include_gutter: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/go_to_line/src/go_to_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl GoToLine {
let end = snapshot.anchor_after(end_point);
editor.highlight_rows::<GoToLineRowHighlights>(
start..end,
cx.theme().colors().editor_highlighted_line_background,
|cx| cx.theme().colors().editor_highlighted_line_background,
RowHighlightOptions {
autoscroll: true,
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/gpui/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ impl From<Hsla> for Background {
}
}
}

impl From<Rgba> for Background {
fn from(value: Rgba) -> Self {
Background {
Expand Down
4 changes: 2 additions & 2 deletions crates/outline/src/outline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl OutlineViewDelegate {
active_editor.clear_row_highlights::<OutlineRowHighlights>();
active_editor.highlight_rows::<OutlineRowHighlights>(
outline_item.range.start..outline_item.range.end,
cx.theme().colors().editor_highlighted_line_background,
|cx| cx.theme().colors().editor_highlighted_line_background,
RowHighlightOptions {
autoscroll: true,
..Default::default()
Expand Down Expand Up @@ -375,7 +375,7 @@ impl PickerDelegate for OutlineViewDelegate {

self.active_editor.update(cx, |active_editor, cx| {
let highlight = active_editor
.highlighted_rows::<OutlineRowHighlights>()
.highlighted_rows::<OutlineRowHighlights>(cx)
.next();
if let Some((rows, _)) = highlight {
active_editor.change_selections(
Expand Down
2 changes: 1 addition & 1 deletion crates/vim/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ impl ShellExec {
}
editor.highlight_rows::<ShellExec>(
input_range.clone().unwrap(),
cx.theme().status().unreachable_background,
|cx| cx.theme().status().unreachable_background,
Default::default(),
cx,
);
Expand Down
Loading