federomero / pretty-json

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

JSON is no longer selected after prettified #56

Closed unmultimedio closed 8 years ago

unmultimedio commented 8 years ago

Hello.

One previous version allowed to prettify the JSON selection, and after the prettify process, the JSON was selected (in case we wanted to tab/untab it). That no longer happens, so it needs to be re-selected again.

Can it be set it back or leave it as optional in the settings?

lexicalunit commented 8 years ago

Hi @unmultimedio. Yep the behavior did change. It was changed to help support the option prettifyOnSaveJSON. Without it, every time you save a JSON document, your cursor would jump around badly and you'd randomly select the entire document.

Probably the best thing to do would be to have Prettifies triggered by a prettifyOnSaveJSON event try to keep the cursor near where it was before the user saved, and for everything else to select the prettified JSON after the command is run.

Sound good? I can get started working on that pretty soon.

unmultimedio commented 8 years ago

@lexicalunit I suppose I'll wait until it's optional, because unfortunately I can't turn on that option prettifyOnSaveJSON. I'm working on an API Blueprint documentation (that has a lot of JSONs within), but the file is not JSON, (is *.apib), and the JSON would be automatically intented to the base. in API Blueprint all JSONs need to be 4-tab indented. That's why it was actually very useful to keep it selected so it would be easy to just hit tab 4 times.

Another way to may be solve this issue would be to keep identation from the first element, for example this:

    {"key":"value"}

becomes into this:

    {
      "key": "value"
    }

instead of this:

{
  "key": "value"
}
lexicalunit commented 8 years ago

@unmultimedio prettifyOnSaveJSON is optional and defaulted off so that shouldn't be an issue. The package should be selecting the pretified JSON for you now whenever you run the command on selected JSON text. Is it not working?

This screencast shows how it should work under the current release. See that before and after the JSON text is selected:

out

unmultimedio commented 8 years ago

@lexicalunit Not working for me like that. Just updated to version 1.6.0 and this is what's happening:

aug-10-2016 10-14-23

The JSON text is not selected after prettified.

lexicalunit commented 8 years ago

@unmultimedio that's definitely a bug then. It's not immediately clear why this is happening for you and not me. I assume you've tried quitting and reloading Atom since updating to 1.6.0?

Are you on Atom-beta or Atom-stable? I'm on beta so that might be a difference between our setups that could account for this differing behavior.

lexicalunit commented 8 years ago

@unmultimedio I created a unit test using the example JSON you provided in your screencast. The test selects the JSON, runs prettify on it, and checks that the entire formatted text is selected afterwards. CI testing shows the test passing on Atom beta and stable, for platforms OS X and Linux.

However I don't have CI setup for Windows at the moment. Are you running Atom on Windows? Perhaps there's an issue with that platform specifically.

unmultimedio commented 8 years ago

@lexicalunit Yes, after updating 1.6.0 I restarted Atom but still happening. Decided to uninstall package, delete folder of the package from atom config folder, and then do a clean reinstall. Now is working fine. For sure it was some config settings that's not clean-updated from previous versions. Thanks a lot for the help!

Update

Running on macOS El Capitan

lexicalunit commented 8 years ago

Whew, that's good to hear! Difficult to reproduce bugs are such a nightmare. Hopefully the unit test I added will ensure there's no regressions on this feature in the future as well. Thanks for the ticket and the help!