From a21c49c015ca05e76e6ed688e9256d9d860a108c Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 7 Nov 2023 14:05:23 -0700 Subject: [PATCH 1/2] Make it possible to render a single line editor --- crates/editor2/src/element.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 2236f8aeaf596caf87678e1962d460ea773ebf35..5af5d97e03ceed35569acbb950e0f75d3fceb7c6 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -1595,7 +1595,7 @@ impl EditorElement { &mut self, editor: &mut Editor, cx: &mut ViewContext<'_, Editor>, - bounds: Bounds, + mut bounds: Bounds, ) -> LayoutState { // let mut size = constraint.max; // if size.x.is_infinite() { @@ -1673,8 +1673,7 @@ impl EditorElement { // .min(line_height * max_lines as f32), // ) } else if let EditorMode::SingleLine = editor_mode { - todo!() - // size.set_y(line_height.max(constraint.min_along(Axis::Vertical))) + bounds.size.height = line_height.min(bounds.size.height); } // todo!() // else if size.y.is_infinite() { From 5c450843a53a3b27688138a58b2befacba363e6d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 7 Nov 2023 14:19:15 -0700 Subject: [PATCH 2/2] Add text and focus to editor --- crates/editor2/src/editor.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 99de3733a16f96fbbad5510c181071b5753c4c7c..c63c531cebddcfa1f807ee5460a54b1976d9c175 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -8363,9 +8363,9 @@ impl Editor { // .max_point() // } - // pub fn text(&self, cx: &AppContext) -> String { - // self.buffer.read(cx).read(cx).text() - // } + pub fn text(&self, cx: &AppContext) -> String { + self.buffer.read(cx).read(cx).text() + } // pub fn set_text(&mut self, text: impl Into>, cx: &mut ViewContext) { // self.transact(cx, |this, cx| { @@ -9185,6 +9185,10 @@ impl Editor { // }); // supports // } + + fn focus(&self, cx: &mut WindowContext) { + cx.focus(&self.focus_handle) + } } pub trait CollaborationHub {