assistant: Fix gutter width (#13373)

The gutter width of the assistant panel was wider then expected after
#13329 was merged.

Release Notes:

- N/A
This commit is contained in:
Bennet Bo Fenner 2024-06-21 19:59:46 +02:00 committed by GitHub
parent d3b3e072a7
commit edca195e3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -2253,6 +2253,7 @@ impl ContextEditor {
editor.set_show_line_numbers(false, cx); editor.set_show_line_numbers(false, cx);
editor.set_show_git_diff_gutter(false, cx); editor.set_show_git_diff_gutter(false, cx);
editor.set_show_code_actions(false, cx); editor.set_show_code_actions(false, cx);
editor.set_show_runnables(false, cx);
editor.set_show_wrap_guides(false, cx); editor.set_show_wrap_guides(false, cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_completion_provider(Box::new(completion_provider)); editor.set_completion_provider(Box::new(completion_provider));

View File

@ -484,6 +484,7 @@ pub struct Editor {
show_line_numbers: Option<bool>, show_line_numbers: Option<bool>,
show_git_diff_gutter: Option<bool>, show_git_diff_gutter: Option<bool>,
show_code_actions: Option<bool>, show_code_actions: Option<bool>,
show_runnables: Option<bool>,
show_wrap_guides: Option<bool>, show_wrap_guides: Option<bool>,
show_indent_guides: Option<bool>, show_indent_guides: Option<bool>,
placeholder_text: Option<Arc<str>>, placeholder_text: Option<Arc<str>>,
@ -566,6 +567,7 @@ pub struct EditorSnapshot {
show_line_numbers: Option<bool>, show_line_numbers: Option<bool>,
show_git_diff_gutter: Option<bool>, show_git_diff_gutter: Option<bool>,
show_code_actions: Option<bool>, show_code_actions: Option<bool>,
show_runnables: Option<bool>,
render_git_blame_gutter: bool, render_git_blame_gutter: bool,
pub display_snapshot: DisplaySnapshot, pub display_snapshot: DisplaySnapshot,
pub placeholder_text: Option<Arc<str>>, pub placeholder_text: Option<Arc<str>>,
@ -1783,6 +1785,7 @@ impl Editor {
show_line_numbers: None, show_line_numbers: None,
show_git_diff_gutter: None, show_git_diff_gutter: None,
show_code_actions: None, show_code_actions: None,
show_runnables: None,
show_wrap_guides: None, show_wrap_guides: None,
show_indent_guides, show_indent_guides,
placeholder_text: None, placeholder_text: None,
@ -2032,6 +2035,7 @@ impl Editor {
show_line_numbers: self.show_line_numbers, show_line_numbers: self.show_line_numbers,
show_git_diff_gutter: self.show_git_diff_gutter, show_git_diff_gutter: self.show_git_diff_gutter,
show_code_actions: self.show_code_actions, show_code_actions: self.show_code_actions,
show_runnables: self.show_runnables,
render_git_blame_gutter: self.render_git_blame_gutter(cx), render_git_blame_gutter: self.render_git_blame_gutter(cx),
display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)), display_snapshot: self.display_map.update(cx, |map, cx| map.snapshot(cx)),
scroll_anchor: self.scroll_manager.anchor(), scroll_anchor: self.scroll_manager.anchor(),
@ -10175,6 +10179,11 @@ impl Editor {
cx.notify(); cx.notify();
} }
pub fn set_show_runnables(&mut self, show_runnables: bool, cx: &mut ViewContext<Self>) {
self.show_runnables = Some(show_runnables);
cx.notify();
}
pub fn set_show_wrap_guides(&mut self, show_wrap_guides: bool, cx: &mut ViewContext<Self>) { pub fn set_show_wrap_guides(&mut self, show_wrap_guides: bool, cx: &mut ViewContext<Self>) {
self.show_wrap_guides = Some(show_wrap_guides); self.show_wrap_guides = Some(show_wrap_guides);
cx.notify(); cx.notify();
@ -11795,7 +11804,7 @@ impl EditorSnapshot {
let gutter_settings = EditorSettings::get_global(cx).gutter; let gutter_settings = EditorSettings::get_global(cx).gutter;
let show_line_numbers = self let show_line_numbers = self
.show_line_numbers .show_line_numbers
.unwrap_or_else(|| gutter_settings.line_numbers); .unwrap_or(gutter_settings.line_numbers);
let line_gutter_width = if show_line_numbers { let line_gutter_width = if show_line_numbers {
// Avoid flicker-like gutter resizes when the line number gains another digit and only resize the gutter on files with N*10^5 lines. // Avoid flicker-like gutter resizes when the line number gains another digit and only resize the gutter on files with N*10^5 lines.
let min_width_for_number_on_gutter = em_width * 4.0; let min_width_for_number_on_gutter = em_width * 4.0;
@ -11806,14 +11815,16 @@ impl EditorSnapshot {
let show_code_actions = self let show_code_actions = self
.show_code_actions .show_code_actions
.unwrap_or_else(|| gutter_settings.code_actions); .unwrap_or(gutter_settings.code_actions);
let show_runnables = self.show_runnables.unwrap_or(gutter_settings.runnables);
let git_blame_entries_width = self let git_blame_entries_width = self
.render_git_blame_gutter .render_git_blame_gutter
.then_some(em_width * GIT_BLAME_GUTTER_WIDTH_CHARS); .then_some(em_width * GIT_BLAME_GUTTER_WIDTH_CHARS);
let mut left_padding = git_blame_entries_width.unwrap_or(Pixels::ZERO); let mut left_padding = git_blame_entries_width.unwrap_or(Pixels::ZERO);
left_padding += if show_code_actions || gutter_settings.runnables { left_padding += if show_code_actions || show_runnables {
em_width * 3.0 em_width * 3.0
} else if show_git_gutter && show_line_numbers { } else if show_git_gutter && show_line_numbers {
em_width * 2.0 em_width * 2.0