Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text_editor panic when backspacing with long lines #2328

Open
2 tasks done
trollham opened this issue Mar 12, 2024 · 0 comments
Open
2 tasks done

text_editor panic when backspacing with long lines #2328

trollham opened this issue Mar 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@trollham
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • 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 trollham added the bug Something isn't working label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant