use gpui::{App, Entity, IntoElement, RenderOnce, Window};
use super::{InputBaseState, TextareaMode};
pub type TextareaState = InputBaseState<TextareaMode>;
#[derive(IntoElement)]
pub struct Textarea {
presentation: super::InlineTokenPresentation,
state: Entity<TextareaState>,
}
impl Textarea {
pub fn new(state: &Entity<TextareaState>) -> Self {
Self {
state: state.clone(),
presentation: Default::default(),
}
}
pub fn token<R: IntoElement>(
mut self,
render: impl Fn(&super::InlineTokenContext, &mut Window, &mut App) -> R + 'static,
) -> Self {
self.presentation = self.presentation.token(render);
self
}
pub fn on_token_click(
mut self,
listener: impl Fn(&super::InlineTokenClickEvent, &mut Window, &mut App) + 'static,
) -> Self {
self.presentation = self.presentation.on_token_click(listener);
self
}
}
impl RenderOnce for Textarea {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
self.state.update(cx, |state, _| {
state.set_token_presentation(self.presentation)
});
self.state
}
}