diff --git a/crates/agent/src/active_thread.rs b/crates/agent/src/active_thread.rs index 05a20e0d56ddfd03b374e6f05d4aef0b915c4904..32378431ad0ce2bcd2530d8b01751f58e3cc9328 100644 --- a/crates/agent/src/active_thread.rs +++ b/crates/agent/src/active_thread.rs @@ -59,7 +59,6 @@ use zed_llm_client::CompletionIntent; const CODEBLOCK_CONTAINER_GROUP: &str = "codeblock_container"; const EDIT_PREVIOUS_MESSAGE_MIN_LINES: usize = 1; -const EDIT_PREVIOUS_MESSAGE_MAX_LINES: usize = 6; pub struct ActiveThread { context_store: Entity, @@ -1330,7 +1329,7 @@ impl ActiveThread { self.thread_store.downgrade(), self.text_thread_store.downgrade(), EDIT_PREVIOUS_MESSAGE_MIN_LINES, - EDIT_PREVIOUS_MESSAGE_MAX_LINES, + None, window, cx, ); @@ -1695,7 +1694,7 @@ impl ActiveThread { let mut editor = Editor::new( editor::EditorMode::AutoHeight { min_lines: 1, - max_lines: 4, + max_lines: Some(4), }, buffer, None, diff --git a/crates/agent/src/inline_prompt_editor.rs b/crates/agent/src/inline_prompt_editor.rs index 31b0c7959560b3535181f8c562b36ba9a9da4f96..81912c82ef81e0b630eef49ab36975ae35bf844b 100644 --- a/crates/agent/src/inline_prompt_editor.rs +++ b/crates/agent/src/inline_prompt_editor.rs @@ -870,7 +870,7 @@ impl PromptEditor { let mut editor = Editor::new( EditorMode::AutoHeight { min_lines: 1, - max_lines: Self::MAX_LINES as usize, + max_lines: Some(Self::MAX_LINES as usize), }, prompt_buffer, None, @@ -1049,7 +1049,7 @@ impl PromptEditor { let mut editor = Editor::new( EditorMode::AutoHeight { min_lines: 1, - max_lines: Self::MAX_LINES as usize, + max_lines: Some(Self::MAX_LINES as usize), }, prompt_buffer, None, diff --git a/crates/agent/src/message_editor.rs b/crates/agent/src/message_editor.rs index ec0a01e8af01f29041a6f4a116fca4761bdc2a8e..842441b18d0659d927b844f61832e299bf26e3a4 100644 --- a/crates/agent/src/message_editor.rs +++ b/crates/agent/src/message_editor.rs @@ -89,7 +89,7 @@ pub(crate) fn create_editor( thread_store: WeakEntity, text_thread_store: WeakEntity, min_lines: usize, - max_lines: usize, + max_lines: Option, window: &mut Window, cx: &mut App, ) -> Entity { @@ -107,7 +107,7 @@ pub(crate) fn create_editor( let mut editor = Editor::new( editor::EditorMode::AutoHeight { min_lines, - max_lines, + max_lines: max_lines, }, buffer, None, @@ -163,7 +163,7 @@ impl MessageEditor { thread_store.clone(), text_thread_store.clone(), MIN_EDITOR_LINES, - MAX_EDITOR_LINES, + Some(MAX_EDITOR_LINES), window, cx, ); @@ -261,7 +261,7 @@ impl MessageEditor { } else { editor.set_mode(EditorMode::AutoHeight { min_lines: MIN_EDITOR_LINES, - max_lines: MAX_EDITOR_LINES, + max_lines: Some(MAX_EDITOR_LINES), }) } }); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 31620a8d883cb66f7abb567b6f74ee2f8784edd1..ea2b15540ece4f030df3a7c41c5b4356ec12dde3 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -487,7 +487,7 @@ pub enum EditorMode { }, AutoHeight { min_lines: usize, - max_lines: usize, + max_lines: Option, }, Full { /// When set to `true`, the editor will scale its UI elements with the buffer font size. @@ -1650,7 +1650,28 @@ impl Editor { Self::new( EditorMode::AutoHeight { min_lines, - max_lines, + max_lines: Some(max_lines), + }, + buffer, + None, + window, + cx, + ) + } + + /// Creates a new auto-height editor with a minimum number of lines but no maximum. + /// The editor grows as tall as needed to fit its content. + pub fn auto_height_unbounded( + min_lines: usize, + window: &mut Window, + cx: &mut Context, + ) -> Self { + let buffer = cx.new(|cx| Buffer::local("", cx)); + let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx)); + Self::new( + EditorMode::AutoHeight { + min_lines, + max_lines: None, }, buffer, None, @@ -22718,7 +22739,7 @@ impl BreakpointPromptEditor { let mut prompt = Editor::new( EditorMode::AutoHeight { min_lines: 1, - max_lines: Self::MAX_LINES as usize, + max_lines: Some(Self::MAX_LINES as usize), }, buffer, None, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index afefc32e4ab85f1114644cf41c8fb862b23f962d..b002a96de8d0e1f615e865b7908c19a5f4bcbbb4 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -9985,7 +9985,7 @@ pub fn register_action( fn compute_auto_height_layout( editor: &mut Editor, min_lines: usize, - max_lines: usize, + max_lines: Option, max_line_number_width: Pixels, known_dimensions: Size>, available_width: AvailableSpace, @@ -10031,11 +10031,18 @@ fn compute_auto_height_layout( } let scroll_height = (snapshot.max_point().row().next_row().0 as f32) * line_height; - let height = scroll_height - .max(line_height * min_lines as f32) - .min(line_height * max_lines as f32); - Some(size(width, height)) + let min_height = line_height * min_lines as f32; + let content_height = scroll_height.max(min_height); + + let final_height = if let Some(max_lines) = max_lines { + let max_height = line_height * max_lines as f32; + content_height.min(max_height) + } else { + content_height + }; + + Some(size(width, final_height)) } #[cfg(test)] @@ -10337,7 +10344,7 @@ mod tests { EditorMode::SingleLine { auto_width: false }, EditorMode::AutoHeight { min_lines: 1, - max_lines: 100, + max_lines: Some(100), }, ] { for show_line_numbers in [true, false] { diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index e79997a06367c71f54ccfdcf82344535848fdeb5..3cc94f84d325e89f2f5f6a9322460b5de07f45ca 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -379,7 +379,7 @@ pub(crate) fn commit_message_editor( let mut commit_editor = Editor::new( EditorMode::AutoHeight { min_lines: 1, - max_lines, + max_lines: Some(max_lines), }, buffer, None, diff --git a/crates/repl/src/notebook/cell.rs b/crates/repl/src/notebook/cell.rs index 30e26579f390cf0882dcdd87c35ad5575a77164e..7bfb2ed69cf7998d560260a989ca7e635d661266 100644 --- a/crates/repl/src/notebook/cell.rs +++ b/crates/repl/src/notebook/cell.rs @@ -179,7 +179,7 @@ impl Cell { let mut editor = Editor::new( EditorMode::AutoHeight { min_lines: 1, - max_lines: 1024, + max_lines: Some(1024), }, multi_buffer, None,