pop-os / libcosmic

WIP library for COSMIC applications
https://pop-os.github.io/libcosmic/cosmic/
Mozilla Public License 2.0
359 stars 32 forks source link

`TextEditor::on_action()` triggers stack overflow when pasting in content #432

Open BrunoWallner opened 2 months ago

BrunoWallner commented 2 months ago

How

I have this simplified example:

#[derive(Clone, Debug)]
pub enum EditorMessage {
    Editor(Action),
}

pub struct Editor {
    content: Content,
}
impl Editor {
    pub fn new() -> Self {
        Self {
            content: Content::new(),
        }
    }
    pub fn view<'a>(&'a self) -> Element<'a, Message> {
        let text = TextEditor::new(&self.content);
        let text = text.on_action(|a| {
            println!("{:?}", a);
            Message::Editor(EditorMessage::Editor(a))
        });

        Element::from(text)
    }

    pub fn update(&mut self, message: EditorMessage) {
        println!("message: {:?}", message);
        match message {
            EditorMessage::Editor(action) => self.content.perform(action),
        };
    }
}

this works well, except when trying to paste in content using CTRL + V. Then it will trigger a stack overflow without being able to print the action. Neither inside on_action(), or inside update().

Info

mmstick commented 2 months ago

Where did you get TextEditor from?

BrunoWallner commented 2 months ago

Where did you get TextEditor from?

from cosmic::iced_widget::TextEditor

BrunoWallner commented 2 months ago

I wrongfully assumed that the problem lies in TextEditor but this bug also happens in iced::widget::TextInput. And it seems like this happens on any other cosmic app too like cosmic-files when trying to paste something into a text input field.

I am on Archlinux: 6.8.9-arch1-2 and this happens on both COSMIC-epoch and Gnome.