Skip to content

text_editor::Content may benefit from an is_empty helper function #3105

@mfreeborn

Description

@mfreeborn

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

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 think it's probably not uncommon to want to check if one's TextEditor content is empty or not.

There isn't a devoted helper method, so, naively, one would just do Content::text().is_empty(). However, that will allocate a String every time.

A better way with the public API as it stands would be something like Content::line_count() == 0 || Content::line_count() == 1 && Content::line(0).unwrap().text.is_empty().

Checking without allocating at all would require access to the private internals.

Does that sound reasonable?

What is the expected behavior?

Not to allocate when checking if the text editor Content is empty.

Version

crates.io release

Operating System

Windows

Do you have any log output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions