auto_height_editor.rs

 1use editor::Editor;
 2use gpui::{
 3    App, AppContext as _, Context, Entity, IntoElement, KeyBinding, ParentElement, Render, Styled,
 4    Window, div, white,
 5};
 6
 7pub struct AutoHeightEditorStory {
 8    editor: Entity<Editor>,
 9}
10
11impl AutoHeightEditorStory {
12    pub fn new(window: &mut Window, cx: &mut App) -> gpui::Entity<Self> {
13        cx.bind_keys([KeyBinding::new(
14            "enter",
15            editor::actions::Newline,
16            Some("Editor"),
17        )]);
18        cx.new(|cx| Self {
19            editor: cx.new(|cx| {
20                let mut editor = Editor::auto_height(1, 3, window, cx);
21                editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
22                editor
23            }),
24        })
25    }
26}
27
28impl Render for AutoHeightEditorStory {
29    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
30        div()
31            .size_full()
32            .bg(white())
33            .text_sm()
34            .child(div().w_32().bg(gpui::black()).child(self.editor.clone()))
35    }
36}