diff --git a/crates/agent_ui/src/acp/entry_view_state.rs b/crates/agent_ui/src/acp/entry_view_state.rs index 4c058b984f4fa24074ea9e9d81e43c1d73d87d1f..382d0ee3c96ef002372046ee6a6111f8e814f892 100644 --- a/crates/agent_ui/src/acp/entry_view_state.rs +++ b/crates/agent_ui/src/acp/entry_view_state.rs @@ -4,7 +4,7 @@ use acp_thread::{AcpThread, AgentThreadEntry}; use agent::HistoryStore; use agent_client_protocol::{self as acp, ToolCallId}; use collections::HashMap; -use editor::{Editor, EditorMode, MinimapVisibility}; +use editor::{Editor, EditorMode, MinimapVisibility, SizingBehavior}; use gpui::{ AnyEntity, App, AppContext as _, Entity, EntityId, EventEmitter, FocusHandle, Focusable, ScrollHandle, SharedString, TextStyleRefinement, WeakEntity, Window, @@ -357,7 +357,7 @@ fn create_editor_diff( EditorMode::Full { scale_ui_elements_with_buffer_font_size: false, show_active_line_background: false, - sized_by_content: true, + sizing_behavior: SizingBehavior::SizeByContent, }, diff.read(cx).multibuffer().clone(), None, diff --git a/crates/agent_ui/src/acp/thread_view.rs b/crates/agent_ui/src/acp/thread_view.rs index 3638faf9336f79d692f820df39266ab7b85360a8..575c8e24f2f0c4907b4e8eb7b4ddcd5f657dfa86 100644 --- a/crates/agent_ui/src/acp/thread_view.rs +++ b/crates/agent_ui/src/acp/thread_view.rs @@ -17,7 +17,9 @@ use client::zed_urls; use cloud_llm_client::PlanV1; use collections::{HashMap, HashSet}; use editor::scroll::Autoscroll; -use editor::{Editor, EditorEvent, EditorMode, MultiBuffer, PathKey, SelectionEffects}; +use editor::{ + Editor, EditorEvent, EditorMode, MultiBuffer, PathKey, SelectionEffects, SizingBehavior, +}; use file_icons::FileIcons; use fs::Fs; use futures::FutureExt as _; @@ -892,7 +894,7 @@ impl AcpThreadView { EditorMode::Full { scale_ui_elements_with_buffer_font_size: false, show_active_line_background: false, - sized_by_content: false, + sizing_behavior: SizingBehavior::ExcludeOverscrollMargin, }, cx, ) diff --git a/crates/debugger_ui/src/session/running/console.rs b/crates/debugger_ui/src/session/running/console.rs index 2d01a325a2b0056bfbf42e519a79a4ec199c4a9d..e157d832b440b8016f152c88b376a9418ee3c843 100644 --- a/crates/debugger_ui/src/session/running/console.rs +++ b/crates/debugger_ui/src/session/running/console.rs @@ -6,7 +6,10 @@ use alacritty_terminal::vte::ansi; use anyhow::Result; use collections::HashMap; use dap::{CompletionItem, CompletionItemType, OutputEvent}; -use editor::{Bias, CompletionProvider, Editor, EditorElement, EditorStyle, ExcerptId}; +use editor::{ + Bias, CompletionProvider, Editor, EditorElement, EditorMode, EditorStyle, ExcerptId, + SizingBehavior, +}; use fuzzy::StringMatchCandidate; use gpui::{ Action as _, AppContext, Context, Corner, Entity, FocusHandle, Focusable, HighlightStyle, Hsla, @@ -59,6 +62,11 @@ impl Console { ) -> Self { let console = cx.new(|cx| { let mut editor = Editor::multi_line(window, cx); + editor.set_mode(EditorMode::Full { + scale_ui_elements_with_buffer_font_size: true, + show_active_line_background: true, + sizing_behavior: SizingBehavior::ExcludeOverscrollMargin, + }); editor.move_to_end(&editor::actions::MoveToEnd, window, cx); editor.set_read_only(true); editor.disable_scrollbars_and_minimap(window, cx); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index bcabf122400e1604aac59c70007aaa472a5a8787..59864cb4b0d34e2816251d0438662f0a564f061e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -452,6 +452,20 @@ pub enum SelectMode { All, } +#[derive(Copy, Clone, Default, PartialEq, Eq, Debug)] +pub enum SizingBehavior { + /// The editor will layout itself using `size_full` and will include the vertical + /// scroll margin as requested by user settings. + #[default] + Default, + /// The editor will layout itself using `size_full`, but will not have any + /// vertical overscroll. + ExcludeOverscrollMargin, + /// The editor will request a vertical size according to its content and will be + /// layouted without a vertical scroll margin. + SizeByContent, +} + #[derive(Clone, PartialEq, Eq, Debug)] pub enum EditorMode { SingleLine, @@ -464,8 +478,8 @@ pub enum EditorMode { scale_ui_elements_with_buffer_font_size: bool, /// When set to `true`, the editor will render a background for the active line. show_active_line_background: bool, - /// When set to `true`, the editor's height will be determined by its content. - sized_by_content: bool, + /// Determines the sizing behavior for this editor + sizing_behavior: SizingBehavior, }, Minimap { parent: WeakEntity, @@ -477,7 +491,7 @@ impl EditorMode { Self::Full { scale_ui_elements_with_buffer_font_size: true, show_active_line_background: true, - sized_by_content: false, + sizing_behavior: SizingBehavior::Default, } } diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 1d277b8b99b5f60f02b450dcc06997b15cd37184..c88d1b5e99680097e0c9db312ea51542b71ca168 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -14094,7 +14094,7 @@ async fn test_completion_in_multibuffer_with_replace_range(cx: &mut TestAppConte EditorMode::Full { scale_ui_elements_with_buffer_font_size: false, show_active_line_background: false, - sized_by_content: false, + sizing_behavior: SizingBehavior::Default, }, multi_buffer.clone(), Some(project.clone()), diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 101b424e4e99c7fdb4ce536d3635db61d8b3bc8e..3b4ec876ed244de8932ea70fbab03fa25176fc13 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -8,8 +8,8 @@ use crate::{ HandleInput, HoveredCursor, InlayHintRefreshReason, JumpData, LineDown, LineHighlight, LineUp, MAX_LINE_LEN, MINIMAP_FONT_SIZE, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT, OpenExcerpts, PageDown, PageUp, PhantomBreakpointIndicator, Point, RowExt, RowRangeExt, SelectPhase, - SelectedTextHighlight, Selection, SelectionDragState, SoftWrap, StickyHeaderExcerpt, ToPoint, - ToggleFold, ToggleFoldAll, + SelectedTextHighlight, Selection, SelectionDragState, SizingBehavior, SoftWrap, + StickyHeaderExcerpt, ToPoint, ToggleFold, ToggleFoldAll, code_context_menus::{CodeActionsMenu, MENU_ASIDE_MAX_WIDTH, MENU_ASIDE_MIN_WIDTH, MENU_GAP}, display_map::{ Block, BlockContext, BlockStyle, ChunkRendererId, DisplaySnapshot, EditorMargins, @@ -8437,11 +8437,11 @@ impl Element for EditorElement { window.request_layout(style, None, cx) } EditorMode::Full { - sized_by_content, .. + sizing_behavior, .. } => { let mut style = Style::default(); style.size.width = relative(1.).into(); - if sized_by_content { + if sizing_behavior == SizingBehavior::SizeByContent { let snapshot = editor.snapshot(window, cx); let line_height = self.style.text.line_height_in_pixels(window.rem_size()); @@ -8605,7 +8605,8 @@ impl Element for EditorElement { EditorMode::SingleLine | EditorMode::AutoHeight { .. } | EditorMode::Full { - sized_by_content: true, + sizing_behavior: SizingBehavior::ExcludeOverscrollMargin + | SizingBehavior::SizeByContent, .. } ) { diff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rs index e3fb30d46eb57059afc53682c57be392ec8254ed..3d840de64d67f5bad7646339d66229ff47831028 100644 --- a/crates/keymap_editor/src/keymap_editor.rs +++ b/crates/keymap_editor/src/keymap_editor.rs @@ -11,7 +11,7 @@ mod ui_components; use anyhow::{Context as _, anyhow}; use collections::{HashMap, HashSet}; -use editor::{CompletionProvider, Editor, EditorEvent}; +use editor::{CompletionProvider, Editor, EditorEvent, EditorMode, SizingBehavior}; use fs::Fs; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ @@ -2788,10 +2788,10 @@ impl ActionArgumentsEditor { let editor = cx.new_window_entity(|window, cx| { let multi_buffer = cx.new(|cx| editor::MultiBuffer::singleton(buffer, cx)); let mut editor = Editor::new( - editor::EditorMode::Full { + EditorMode::Full { scale_ui_elements_with_buffer_font_size: true, show_active_line_background: false, - sized_by_content: true, + sizing_behavior: SizingBehavior::SizeByContent, }, multi_buffer, project.upgrade(),