iced icon indicating copy to clipboard operation
iced copied to clipboard

text_editor panic when backspacing with long lines

Open trollham opened this issue 3 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Is this issue related to iced?

  • [X] My hardware is compatible and my graphics drivers are up-to-date.

What happened?

I ran into a panic when using a text_editor with content that is long enough that it should line-wrapped, but doesn't contain any spaces to wrap on. To reproduce, enter a line with two words, one short and one long enough to overflow the container. Backspace through the shorter word, and the application will panic.

Minimal reproducible example:

use iced::{widget::text_editor, Sandbox, Settings};

const TEXT: &str = r#"
short line
erase this "line" Loremipsumdolorsitamet,consecteturadipiscingelit.Vestibulumvenenatisegetelitidconsectetur.Praesentatdiamsem.
more short line
"#;


fn main() -> iced::Result{
    Ui::run(Settings::default())
}

struct Ui {
    content: text_editor::Content
}
#[derive(Debug, Clone)]
enum Message { Edit(text_editor::Action) }
impl Sandbox for Ui {
    type Message = Message;

    fn new() -> Self {
        Ui { content: text_editor::Content::with_text(TEXT) }
    }

    fn title(&self) -> String {
        "".to_string()
    }

    fn update(&mut self, message: Self::Message) { 
        match message {
            Message::Edit(action) => self.content.perform(action),
        }
    }

    fn view(&self) -> iced::Element<'_, Self::Message> {
        text_editor(&self.content).on_action(Message::Edit).padding(10).into()
    }
}

What is the expected behavior?

The long word is on its own line without the application panicking.

Version

crates.io release

Operating System

Windows

Do you have any log output?

thread 'main' panicked at G:\packages\cargo\registry\src\index.crates.io-6f17d22bba15001f\iced_graphics-0.12.1\src\text\editor.rs:205:35:
attempt to subtract with overflow

trollham avatar Mar 12 '24 22:03 trollham