From 23f191450e8ae0ad2883122114e6fae7accc9a91 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 2 May 2024 12:22:51 +0200 Subject: [PATCH] Do not show inline blame information on empty lines (#11294) cc @iamnbutler Release Notes: - Changed inline git blame information to not show up on empty lines. Demo/proof: https://github.com/zed-industries/zed/assets/1185253/e506cf1f-81b1-407b-8dc7-1666b31ae142 --- crates/editor/src/editor.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 76f75aae700d66575cdb301d7b27dd335310d97c..86ed6d71b83cbc8f1fa8e5a2ae8c54c6cf08063f 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -9114,7 +9114,10 @@ impl Editor { } pub fn render_git_blame_inline(&mut self, cx: &mut WindowContext) -> bool { - self.focus_handle.is_focused(cx) && self.show_git_blame_inline && self.has_blame_entries(cx) + self.show_git_blame_inline + && self.focus_handle.is_focused(cx) + && !self.newest_selection_head_on_empty_line(cx) + && self.has_blame_entries(cx) } fn has_blame_entries(&self, cx: &mut WindowContext) -> bool { @@ -9122,6 +9125,15 @@ impl Editor { .map_or(false, |blame| blame.read(cx).has_generated_entries()) } + fn newest_selection_head_on_empty_line(&mut self, cx: &mut WindowContext) -> bool { + let cursor_anchor = self.selections.newest_anchor().head(); + + let snapshot = self.buffer.read(cx).snapshot(cx); + let buffer_row = cursor_anchor.to_point(&snapshot).row; + + snapshot.line_len(buffer_row) == 0 + } + fn get_permalink_to_line(&mut self, cx: &mut ViewContext) -> Result { let (path, repo) = maybe!({ let project_handle = self.project.as_ref()?.clone();