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

TextEdit strips \r characters and doesn't remember that they were there, causing data loss #101106

Open
wareya opened this issue Jan 3, 2025 · 0 comments

Comments

@wareya
Copy link
Contributor

wareya commented Jan 3, 2025

Tested versions

4.4.dev7

System information

Godot v4.4.dev7 - Windows 10 (build 19045) - Multi-window, 2 monitors - OpenGL 3 (Compatibility) - AMD Radeon RX 6800 (Advanced Micro Devices, Inc.; 32.0.12033.1030) - AMD Ryzen 5 7600X 6-Core Processor (12 threads)

Issue description

When assigning the text of a TextEdit node, it completely loses all information about whether the assigned string originally contained any \r characters at all. It can't even differentiate a consistently \r\n buffer from a \n buffer, and the API doesn't provide a way to recover this information. This happens even if you assign individual lines containing \r characters with set_line.

This also means that any files edited with Godot's built-in script editor will immediately lose their \rs upon being saved, causing data loss. In some cases, e.g. with text file processing test cases, this is a problem even if you're ideologically opposed to \r\n linefeeds.

To some extent some amount of information loss here is expectable because LineEdit is (apparently) based on an array of single-line strings without line terminators, but it should probably at least attempt to detect LF vs CRLF and restore that information when generating the output of get_text(), at least in simple cases like when \n never appears without a preceding \r. A way to query and override this detection would also be nice.

Also, \r characters should never be silently stripped from the middles of lines. Such characters can be the result of e.g. terminal capture logging, where \r literally means "go back to the start of the line and start typing from there again".

Steps to reproduce

Assign "\r\n\r\nasdf\rasdf\rasdf\rasdf" to a TextEdit's text field and note that all the \r characters completely disappear (e.g. by running print(editor.text.c_escape())).

Minimal reproduction project (MRP)

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants