auto_height_editor.rs

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