Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Remove auto-width editor type (#34438)
Cole Miller3ecdfc9b5adb
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 72470c0a7d1..acd9c23c976 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -482,9 +482,7 @@ pub enum SelectMode {#[derive(Clone, PartialEq, Eq, Debug)]pub enum EditorMode {- SingleLine {- auto_width: bool,- },+ SingleLine,AutoHeight {min_lines: usize,max_lines: Option<usize>,@@ -1662,13 +1660,7 @@ impl Editor {pub fn single_line(window: &mut Window, cx: &mut Context<Self>) -> Self {let buffer = cx.new(|cx| Buffer::local("", cx));let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));- Self::new(- EditorMode::SingleLine { auto_width: false },- buffer,- None,- window,- cx,- )+ Self::new(EditorMode::SingleLine, buffer, None, window, cx)}pub fn multi_line(window: &mut Window, cx: &mut Context<Self>) -> Self {@@ -1677,18 +1669,6 @@ impl Editor {Self::new(EditorMode::full(), buffer, None, window, cx)}- pub fn auto_width(window: &mut Window, cx: &mut Context<Self>) -> Self {- let buffer = cx.new(|cx| Buffer::local("", cx));- let buffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));- Self::new(- EditorMode::SingleLine { auto_width: true },- buffer,- None,- window,- cx,- )- }-pub fn auto_height(min_lines: usize,max_lines: usize,diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 06fb52cdb3a..e77be3398ca 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -7787,46 +7787,13 @@ impl Element for EditorElement {editor.set_style(self.style.clone(), window, cx);let layout_id = match editor.mode {- EditorMode::SingleLine { auto_width } => {+ EditorMode::SingleLine => {let rem_size = window.rem_size();-let height = self.style.text.line_height_in_pixels(rem_size);- if auto_width {- let editor_handle = cx.entity().clone();- let style = self.style.clone();- window.request_measured_layout(- Style::default(),- move |_, _, window, cx| {- let editor_snapshot = editor_handle- .update(cx, |editor, cx| editor.snapshot(window, cx));- let line = Self::layout_lines(- DisplayRow(0)..DisplayRow(1),- &editor_snapshot,- &style,- px(f32::MAX),- |_| false, // Single lines never soft wrap- window,- cx,- )- .pop()- .unwrap();-- let font_id =- window.text_system().resolve_font(&style.text.font());- let font_size =- style.text.font_size.to_pixels(window.rem_size());- let em_width =- window.text_system().em_width(font_id, font_size).unwrap();-- size(line.width + em_width, height)- },- )- } else {- let mut style = Style::default();- style.size.height = height.into();- style.size.width = relative(1.).into();- window.request_layout(style, None, cx)- }+ let mut style = Style::default();+ style.size.height = height.into();+ style.size.width = relative(1.).into();+ window.request_layout(style, None, cx)}EditorMode::AutoHeight {min_lines,@@ -10390,7 +10357,7 @@ mod tests {});for editor_mode_without_invisibles in [- EditorMode::SingleLine { auto_width: false },+ EditorMode::SingleLine,EditorMode::AutoHeight {min_lines: 1,max_lines: Some(100),diff --git a/crates/rules_library/src/rules_library.rs b/crates/rules_library/src/rules_library.rsindex f871416f391..be6a69c23be 100644--- a/crates/rules_library/src/rules_library.rs+++ b/crates/rules_library/src/rules_library.rs@@ -611,7 +611,7 @@ impl RulesLibrary {this.update_in(cx, |this, window, cx| match rule {Ok(rule) => {let title_editor = cx.new(|cx| {- let mut editor = Editor::auto_width(window, cx);+ let mut editor = Editor::single_line(window, cx);editor.set_placeholder_text("Untitled", cx);editor.set_text(rule_metadata.title.unwrap_or_default(), window, cx);if prompt_id.is_built_in() {