diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 1f9f614275..ff5bed98fb 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1943,13 +1943,8 @@ impl Editor { cx.notify(); } - pub fn set_current_line_highlight( - &mut self, - current_line_highlight: CurrentLineHighlight, - cx: &mut ViewContext, - ) { + pub fn set_current_line_highlight(&mut self, current_line_highlight: CurrentLineHighlight) { self.current_line_highlight = current_line_highlight; - cx.notify(); } pub fn set_collapse_matches(&mut self, collapse_matches: bool) { diff --git a/crates/editor/src/hunk_diff.rs b/crates/editor/src/hunk_diff.rs index 73c71f4dca..022fed5835 100644 --- a/crates/editor/src/hunk_diff.rs +++ b/crates/editor/src/hunk_diff.rs @@ -10,6 +10,7 @@ use language::Buffer; use multi_buffer::{ Anchor, ExcerptRange, MultiBuffer, MultiBufferRow, MultiBufferSnapshot, ToPoint, }; +use settings::{Settings, SettingsStore}; use text::{BufferId, Point}; use ui::{ div, ActiveTheme, Context as _, IntoElement, ParentElement, Styled, ViewContext, VisualContext, @@ -17,9 +18,10 @@ use ui::{ use util::{debug_panic, RangeExt}; use crate::{ + editor_settings::CurrentLineHighlight, git::{diff_hunk_to_display, DisplayDiffHunk}, hunk_status, hunks_for_selections, BlockDisposition, BlockId, BlockProperties, BlockStyle, - DiffRowHighlight, Editor, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt, + DiffRowHighlight, Editor, EditorSettings, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt, RevertSelectedHunks, ToDisplayPoint, ToggleHunkDiff, }; @@ -580,12 +582,32 @@ fn editor_with_deleted_text( .anchor_after(editor.buffer.read(cx).len(cx)); editor.highlight_rows::(start..=end, Some(deleted_color), cx); - let hunk_related_subscription = cx.on_blur(&editor.focus_handle, |editor, cx| { - editor.change_selections(None, cx, |s| { - s.try_cancel(); - }); - }); - editor._subscriptions.push(hunk_related_subscription); + + let subscription_editor = parent_editor.clone(); + editor._subscriptions.extend([ + cx.on_blur(&editor.focus_handle, |editor, cx| { + editor.set_current_line_highlight(CurrentLineHighlight::None); + editor.change_selections(None, cx, |s| { + s.try_cancel(); + }); + cx.notify(); + }), + cx.on_focus(&editor.focus_handle, move |editor, cx| { + let restored_highlight = if let Some(parent_editor) = subscription_editor.upgrade() + { + parent_editor.read(cx).current_line_highlight + } else { + EditorSettings::get_global(cx).current_line_highlight + }; + editor.set_current_line_highlight(restored_highlight); + cx.notify(); + }), + cx.observe_global::(|editor, cx| { + if !editor.is_focused(cx) { + editor.set_current_line_highlight(CurrentLineHighlight::None); + } + }), + ]); let original_multi_buffer_range = hunk.multi_buffer_range.clone(); let diff_base_range = hunk.diff_base_byte_range.clone(); editor.register_action::(move |_, cx| {