federomero / pretty-json

Atom plugin. Format JSON documents.
MIT License
94 stars 23 forks source link

Cursor jumping around after formatting #87

Open piccolbo opened 3 years ago

piccolbo commented 3 years ago

Potentially related to #56. I have prettify on save on and autosave-on-change on with a delay of 1s. I just like to keep my json formatted and saved all the time, because formatting and saving are good things, and pressing key combinations again and again is a bad thing. Sometime in the middle of filling in a value, the formatting is triggered and when I continue typing the cursor moved out of the matching quotes, in fact out of the surrounding {} and 1 line up. So I go from

{"name": "John"}

to

{Smith
  "name": "John "
}

When I realize things have gone awry and stop typing. It gets old pretty quickly. Unlike #56 I am not selecting anything in this case. Would it be possible to preserve cursor position with respect to the text? I understand newlines are inserted by prettifying, but the cursor should be positioned, in my view, between the last two characters it was positioned in between, unless a newline is inserted at that position, which may complicate things.