mapeditor/tiled

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Unify line breaks #3813

parasyte posted onGitHub

Is your feature request related to a problem? Please describe.

The JSON exporter saves *.tmj files on macOS with "LF" \n line breaks, as expected. On Windows, the exporter saves with "CRLF" \r\n line breaks. This causes git to warn about spurious line break changes when saving a map that otherwise has no differences.

Describe the solution you'd like

UTF-8 and Unix line breaks are the De Facto standard for text-based files, and any text editor worth its salt can read and write these files without issue, across all platforms.

Unify line breaks when exporting text files to "LF" \n on all platforms.

Describe alternatives you've considered

There is no alternative. Windows line breaks are ancient technology, just like UTF-16.

In seriousness, I did have some minor success by switching to the json1.dll plugin in the Windows build. While this plugin does save JSON files with Unix line breaks, it also changes the embedded version number to "1.1" (the json.dll plugin saves with version "1.10").

I chose to stick with the default json.dll plugin and created this ticket to track the issue. I can always use dos2unix if I really need to fix up the line breaks locally.


json1.dll saves custom properties in a different way which may not be compatible with newer parsers, and as such is not a suitable workaround in many cases.

+1 for consistency, either via only using \n or by providing an option within Tiled. I'm on Windows, but would be quite happy with \n.

posted by eishiya over 1 year ago

I'm really surprised by the observed difference between the json and json1 plugins, given that they both open the target file in text mode and should hence observe system-dependent line endings.

Regardless, I'm afraid this behavior would need to be configurable since I'm not sure everybody would agree that CRLF is "ancient technology". Many people may rely on Git to help translate line endings on checkout / checkin, so would have their JSON files on Windows using \r\n but just \n on Linux and macOS, and if Tiled would save on Windows with \n it might cause issues for them (I haven't checked, of course).

I'm not sure when Windows Notepad learned to open LF files correctly, but for a long this time this editor could not and I think it was the main reason to keep saving text files with CRLF on Windows...

posted by bjorn over 1 year ago

A line endings: [OS default / LF / CRLF] dropdown would be neat. I wouldn't be surprised if there were some games out there expecting specifically CRLF tripping up Mac users xP

On a related note, it'd be nice if this and the minify option were exposed to scripting, so that they could affect custom export formats as well.

Edit: Presumably this should also affect storage of string custom property values?

posted by eishiya over 1 year ago

I'm not sure when Windows Notepad learned to open LF files correctly, but for a long this time this editor could not and I think it was the main reason to keep saving text files with CRLF on Windows...

I believe that happened in 2018: https://devblogs.microsoft.com/commandline/extended-eol-in-notepad/

Making line endings configurable is a fair compromise, even if there isn’t a good reason to continue saving with CRLF on Windows by default.

As a contrast, I don’t see anyone arguing to add “CR” line endings as an option for Classic Mac OS! Those are even more obsolete than CRLF; a transition which started with the introduction of Mac OS X in 2001.

posted by parasyte over 1 year ago

As a contrast, I don’t see anyone arguing to add “CR” line endings as an option for Classic Mac OS!

Well, obviously, because nobody is running Mac OS 9 anymore... but if you would somehow be able to port Tiled to it, it would use "CR" for text files written there. :-)

But yeah, at least Notepad has supported LF for about 4 years now, and personally I also think we could use it by default as part of adding the option to use native line-endings.

posted by bjorn over 1 year ago

but if you would somehow be able to port Tiled to it, it would use "CR" for text files written there. :-)

In theory, yes! Although json1.dll should write files with CRLF on Windows if that was true in general.

posted by parasyte over 1 year ago

CRLF is still the default for Windows (Notepad in Windows 10, not sure about 11, I expect it is the same).

Is this issue specifically about JSON output? I was working on a feature request for an option in the editor to select EOL in the settings for exported/saved maps.

I started working on adding the feature to potentially create a PR. But if this is already in the works then I will discontinue it.

posted by AntumDeluge about 1 year ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests