use iced::advanced::text::Wrapping; use iced::widget::operation::focus_next; use iced::widget::{center, column, text_editor}; use iced::{Center, Element, Task}; use iced_selection::text; fn main() -> iced::Result { iced::application(State::new, State::update, State::view).run() } #[derive(Default)] struct State { content: text_editor::Content, name: String, } #[derive(Debug, Clone)] enum Message { UpdateText(text_editor::Action), } impl State { fn new() -> (Self, Task) { (Self::default(), focus_next()) } fn update(&mut self, message: Message) { match message { Message::UpdateText(action) => { let is_edit = action.is_edit(); self.content.perform(action); if is_edit { self.name = self.content.text(); } } }; } fn view(&self) -> Element<'_, Message> { center( column![ text!("Hello {}", &self.name).wrapping(Wrapping::None), text_editor(&self.content).on_action(Message::UpdateText) ] .spacing(10) .align_x(Center), ) .into() } }