linuxmint / xed

X-Apps [Text] Editor (Cross-DE, backward-compatible, GTK3, traditional UI)
GNU General Public License v2.0
445 stars 84 forks source link

Incorrect functioning of xed with the 'Ensure Trailing Newline' option (=ON) #608

Open jp9753 opened 9 months ago

jp9753 commented 9 months ago
 * Xed version 3.2.2
 * Distribution - Mint 20.3

Issue Incorrect functioning of xed with the 'Ensure Trailing Newline' option (=ON)

Steps to reproduce Edit > Preferences > Save > 'Ensure Trailing Newline' = ON Create New Document save 'as CR.txt' check file length (of CR.txt) = 0 (WRONG, option 'Ensure Trailing Newline' should of added a CR to end)

then edit (in xed) the empty file 'CR.txt' type in a single CR (a Return/Enter) save check file length (of CR.txt) = 2 (WRONG!, 'Ensure Trailing Newline' should NOT of added a CR to end)

Expected behaviour The wording of 'Ensure Trailing Newline' implies that a test is performed (before saving) making sure that the final character in, any saved file is a Newline.

If I have misinterpreted the intended operation of 'Ensure Trailing Newline', then I would suggest changing the description to make its purpose clearer.

Interesting question as too what is the 'expected behaviour'

my opinion is: (for files 'edited' with XED with the option 'Ensure Trailing Newline' (=ON))

If a file, (of any length, including zero length), is loaded, (NOT edited) and then a 'close the file' is requested, 'Ensure Trailing Newline' should NOT be run, and therefore no 'Newline' could be added.

If a file, (of any length, including zero length), is loaded, EDITED and then a 'close the file' is requested, 'Ensure Trailing Newline' should then be run and any 'Newline' added (if required) (even if it is a zero length file), concluding with the 'Close Without Saving, Cancel, Save' dialog.

If a file, (of any length, including zero length), is loaded, and then 'Save or Save As' is requested, 'Ensure Trailing Newline' should then be run and any 'Newline' added (if required) (even if it has not been edited and/or it is a zero length file), again concluding with the 'Close Without Saving, Cancel, Save' dialog.

Other information

ghost commented 3 weeks ago

Create New Document save 'as CR.txt' check file length (of CR.txt) = 0 (WRONG, option 'Ensure Trailing Newline' should of added a CR to end)

You created an empty file (=0 lines), so there are no incomplete lines, therefore this is expected.

then edit (in xed) the empty file 'CR.txt' type in a single CR (a Return/Enter) save check file length (of CR.txt) = 2 (WRONG!, 'Ensure Trailing Newline' should NOT of added a CR to end)

This one is ambiguous, it depends on whether you treat Enter as "end the current line" (in which case you're right) or as "start a new line" (which xed seems to be doing, implicitly terminating the last line). So neither is wrong, just depends on how you see it.

The wording of 'Ensure Trailing Newline' implies that a test is performed (before saving) making sure that the final character in, any saved file is a Newline.

If I have misinterpreted the intended operation of 'Ensure Trailing Newline', then I would suggest changing the description to make its purpose clearer.

I agree that the wording is confusing, since it doesn't (and shouldn't) add a newline to an empty file. It should probably say something like "... for non-empty files".

If a file, (of any length, including zero length), is loaded, (NOT edited) and then a 'close the file' is requested, 'Ensure Trailing Newline' should NOT be run, and therefore no 'Newline' could be added.

Of course, files shouldn't be edited automatically.

If a file, (of any length, including zero length), is loaded, EDITED and then a 'close the file' is requested, 'Ensure Trailing Newline' should then be run and any 'Newline' added (if required) (even if it is a zero length file), concluding with the 'Close Without Saving, Cancel, Save' dialog.

If a file, (of any length, including zero length), is loaded, and then 'Save or Save As' is requested, 'Ensure Trailing Newline' should then be run and any 'Newline' added (if required) (even if it has not been edited and/or it is a zero length file), again concluding with the 'Close Without Saving, Cancel, Save' dialog.

As said before, newlines shouldn't be added to empty files. Otherwise, this is correct.

Note: Linux uses LF as line ending, not CR.

Relevant definitions: Empty Line Incomplete Line Line Text File