JSON-Viewer
JSON-Viewer copied to clipboard
Format JSON doesn't keep line break when formatting a selected line
Hello, please have a look at the following issue:
Initial file is a list of JSON data on each line.
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.
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
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.
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.
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.