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::Content.text() gives inconsistent/misleading results #2730

Open
4 tasks done
CyberCeisc opened this issue Jan 16, 2025 · 0 comments
Open
4 tasks done

text_editor::Content.text() gives inconsistent/misleading results #2730

CyberCeisc opened this issue Jan 16, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@CyberCeisc
Copy link

CyberCeisc commented Jan 16, 2025

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?

text_editor::Content::text() appends a newline character ('\n') to the end of the returned string if there is not one present.

This causes issues/inconsistencies when the actual content of the text_editor genuinely ends with a newline character.

For example, if I have a text_editor with no content in it, it displays on the screen as a box with a single line. At this point calling text() on its content returns a string with a length of 1 and content of "\n".

If I then focus on the text_editor and hit return, the display correctly changes to a box with two lines. At this point, however, calling text() on the content returns a string with a length of 1 and content of "\n".

Clearly at this stage the actual content of the text_editors is different but I have no way of determining this when calling text() as it returns identical results for two different situations.

This issue is due to the check on lines 410-412 of widget/src/text_editor.rs:

        if !text.ends_with('\n') {
            text.push('\n');
        }

What is the expected behavior?

I expect to be able to unambiguously determine the content of the text_editor and relate it correctly to what is displayed on the screen.

Options I can see for this are:

  • Always add a newline character to the string returned by text(), allowing the consumer to handle removing the newline to get to the actual content
  • Never add a newline, leaving the consumer to add their own newline should that fit their purposes

Personally, I would prefer that the response didn't add the newline so that what is returned to me is what is actually in the text_editor.

Version

master

Operating System

Linux

Do you have any log output?

@CyberCeisc CyberCeisc added the bug Something isn't working label Jan 16, 2025
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