gpui_base/input/textarea/
mod.rs1use gpui::{App, Entity, IntoElement, RenderOnce, Window};
2
3use super::{InputBaseState, TextareaMode};
4
5pub type TextareaState = InputBaseState<TextareaMode>;
11
12#[derive(IntoElement)]
14pub struct Textarea {
15 presentation: super::InlineTokenPresentation,
16 state: Entity<TextareaState>,
17}
18
19impl Textarea {
20 pub fn new(state: &Entity<TextareaState>) -> Self {
21 Self {
22 state: state.clone(),
23 presentation: Default::default(),
24 }
25 }
26 pub fn token<R: IntoElement>(
28 mut self,
29 render: impl Fn(&super::InlineTokenContext, &mut Window, &mut App) -> R + 'static,
30 ) -> Self {
31 self.presentation = self.presentation.token(render);
32 self
33 }
34 pub fn on_token_click(
36 mut self,
37 listener: impl Fn(&super::InlineTokenClickEvent, &mut Window, &mut App) + 'static,
38 ) -> Self {
39 self.presentation = self.presentation.on_token_click(listener);
40 self
41 }
42}
43
44impl RenderOnce for Textarea {
45 fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
46 self.state.update(cx, |state, _| {
47 state.set_token_presentation(self.presentation)
48 });
49 self.state
50 }
51}