JSON-Viewer icon indicating copy to clipboard operation
JSON-Viewer copied to clipboard

Format JSON doesn't keep line break when formatting a selected line

Open scrontch opened this issue 4 years ago • 3 comments

Hello, please have a look at the following issue:

Initial file is a list of JSON data on each line.

2020-05-18 16_39_13-Window

I select a whole line by clicking on the line header. I Format JSON (Ctrl+Alt+Shift+M) the selected text. Result is the text is formatted, but the line-break of the line has been eaten up. The start of the next line now starts directly after the last character of the formatted JSON.

2020-05-18 16_40_31-Window

scrontch avatar May 18 '20 15:05 scrontch

It seems this can be solved by adding an extra newline character to the formatted string. But, don't know if that could break something else. Any suggestions on this ? @scrontch

kapilratnani avatar Jul 04 '20 08:07 kapilratnani

Hi, sorry, forgot to answer Well, for me it would solve the problem. Ideally, the newline should be added only if the selected string contained a newline as last character.

scrontch avatar Nov 16 '20 13:11 scrontch

Another point of view to the issue: Since clicking on the line header selects the whole line, including newline control characters, I think it makes sense that they are replaced. You can select the whole line without those characters with shift+end keys to keep the newline character(s).

I think the main issue is that it is weird that characters outside the selection could end in the same line as one of those in the formatted JSON string (that is, its first and last line). To address that, I'd suggest to add a new line at the beginning if the selection doesn't start at the beginning of a line, and to add a new line at the end if the selection doesn't finish at the end of a line (before newline characters). That includes the solution already proposed, but also considering the cases where the selection start or finish midline.

user21760 avatar Nov 10 '21 17:11 user21760

Actually this should be addressed in notepad++ itself. When line is selected using line header, and if we press any key. Then same behavior is observed. So this could be an intended notepad++ use case as well.

SinghRajenM avatar Oct 02 '22 15:10 SinghRajenM