1use editor::Editor;
2use gpui::{
3 div, white, IntoElement, KeyBinding, ParentElement, Render, Styled, View, ViewContext,
4 VisualContext, 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.new_view(|cx| Self {
15 editor: cx.new_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 fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
26 div()
27 .size_full()
28 .bg(white())
29 .text_sm()
30 .child(div().w_32().bg(gpui::black()).child(self.editor.clone()))
31 }
32}