agent: Keep horizontal scrollbar in edit file tool cards (#31510)

Previously disabled both scrollbars, but horizontal scrolling is still
needed when
lines exceed the viewport width. Now editors can disable a single scroll
axis, not just both.

Release Notes:

- N/A
This commit is contained in:
Ben Brandt 2025-05-27 17:24:22 +02:00 committed by GitHub
parent 8faeb34367
commit b5c2b25a76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 11 deletions

View file

@ -9,7 +9,7 @@ use assistant_tool::{
ToolUseStatus,
};
use buffer_diff::{BufferDiff, BufferDiffSnapshot};
use editor::{Editor, EditorMode, MultiBuffer, PathKey};
use editor::{Editor, EditorMode, MinimapVisibility, MultiBuffer, PathKey};
use futures::StreamExt;
use gpui::{
Animation, AnimationExt, AnyWindowHandle, App, AppContext, AsyncApp, Entity, EntityId, Task,
@ -428,7 +428,9 @@ impl EditFileToolCard {
editor.set_show_gutter(false, cx);
editor.disable_inline_diagnostics();
editor.disable_expand_excerpt_buttons(cx);
editor.disable_scrollbars_and_minimap(window, cx);
// Keep horizontal scrollbar so user can scroll horizontally if needed
editor.set_show_vertical_scrollbar(false, cx);
editor.set_minimap_visibility(MinimapVisibility::Disabled, window, cx);
editor.set_soft_wrap_mode(SoftWrap::None, cx);
editor.scroll_manager.set_forbid_vertical_scroll(true);
editor.set_show_indent_guides(false, cx);

View file

@ -63,8 +63,8 @@ use dap::TelemetrySpawnLocation;
use display_map::*;
pub use display_map::{ChunkRenderer, ChunkRendererContext, DisplayPoint, FoldPlaceholder};
pub use editor_settings::{
CurrentLineHighlight, EditorSettings, HideMouseMode, ScrollBeyondLastLine, SearchSettings,
ShowScrollbar,
CurrentLineHighlight, EditorSettings, HideMouseMode, ScrollBeyondLastLine, ScrollbarAxes,
SearchSettings, ShowScrollbar,
};
use editor_settings::{GoToDefinitionFallback, Minimap as MinimapSettings};
pub use editor_settings_controls::*;
@ -961,7 +961,7 @@ pub struct Editor {
mode: EditorMode,
show_breadcrumbs: bool,
show_gutter: bool,
show_scrollbars: bool,
show_scrollbars: ScrollbarAxes,
minimap_visibility: MinimapVisibility,
offset_content: bool,
disable_expand_excerpt_buttons: bool,
@ -1801,7 +1801,10 @@ impl Editor {
project,
blink_manager: blink_manager.clone(),
show_local_selections: true,
show_scrollbars: full_mode,
show_scrollbars: ScrollbarAxes {
horizontal: full_mode,
vertical: full_mode,
},
minimap_visibility: MinimapVisibility::for_mode(&mode, cx),
offset_content: !matches!(mode, EditorMode::SingleLine { .. }),
show_breadcrumbs: EditorSettings::get_global(cx).toolbar.breadcrumbs,
@ -16999,8 +17002,21 @@ impl Editor {
cx.notify();
}
pub fn set_show_scrollbars(&mut self, show_scrollbars: bool, cx: &mut Context<Self>) {
self.show_scrollbars = show_scrollbars;
pub fn set_show_scrollbars(&mut self, show: bool, cx: &mut Context<Self>) {
self.show_scrollbars = ScrollbarAxes {
horizontal: show,
vertical: show,
};
cx.notify();
}
pub fn set_show_vertical_scrollbar(&mut self, show: bool, cx: &mut Context<Self>) {
self.show_scrollbars.vertical = show;
cx.notify();
}
pub fn set_show_horizontal_scrollbar(&mut self, show: bool, cx: &mut Context<Self>) {
self.show_scrollbars.horizontal = show;
cx.notify();
}

View file

@ -1465,7 +1465,10 @@ impl EditorElement {
window: &mut Window,
cx: &mut App,
) -> Option<EditorScrollbars> {
if !self.editor.read(cx).show_scrollbars || self.style.scrollbar_width.is_zero() {
let show_scrollbars = self.editor.read(cx).show_scrollbars;
if (!show_scrollbars.horizontal && !show_scrollbars.vertical)
|| self.style.scrollbar_width.is_zero()
{
return None;
}
@ -1510,7 +1513,12 @@ impl EditorElement {
};
Some(EditorScrollbars::from_scrollbar_axes(
scrollbar_settings.axes,
ScrollbarAxes {
horizontal: scrollbar_settings.axes.horizontal
&& self.editor.read(cx).show_scrollbars.horizontal,
vertical: scrollbar_settings.axes.vertical
&& self.editor.read(cx).show_scrollbars.vertical,
},
scrollbar_layout_information,
content_offset,
scroll_position,
@ -7558,7 +7566,7 @@ impl Element for EditorElement {
let scrollbars_shown = settings.scrollbar.show != ShowScrollbar::Never;
let vertical_scrollbar_width = (scrollbars_shown
&& settings.scrollbar.axes.vertical
&& self.editor.read(cx).show_scrollbars)
&& self.editor.read(cx).show_scrollbars.vertical)
.then_some(style.scrollbar_width)
.unwrap_or_default();
let minimap_width = self