Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When beautify on save, don't unfold all the current code folds #116

Closed
toddbluhm opened this issue Oct 6, 2014 · 13 comments
Closed

When beautify on save, don't unfold all the current code folds #116

toddbluhm opened this issue Oct 6, 2014 · 13 comments

Comments

@toddbluhm
Copy link

I have, beautify-on-save checked and when I save one of my js files, it unfolds all the code blocks I have folded up so then I have to go back and refold them all. This is by no means a high priority issue, but more something that would be a really nice enhancement to have.

I also understand this might be something completely out of atom-beautifiers control too.

@Glavin001
Copy link
Owner

Will have to do a little research to investigate if that is doable from my end with Atom Beautify. Beautification writes out beautified code to the editor, consequently removing all the un/fold marks and then re-creating them for the new code.

Thanks for bringing this issue to my attention. Hopefully something can be figured out.

@Glavin001
Copy link
Owner

May be able to accomplish this in the same way it works currently for cursors (save previous states, and restore after beautify): https://github.com/Glavin001/atom-beautify/blob/master/lib/beautify.coffee#L30-L48

Since the code has the potential to change dramatically, this may not work.

@toddbluhm
Copy link
Author

Awesome! Thank you so much for looking into this. Sounds like you have a place to start. Thanks for keeping me updated. I look forward to trying it out if you get it working :)

@Glavin001 Glavin001 added this to the v0.28.0 milestone May 5, 2015
@Glavin001 Glavin001 removed this from the v0.28.0 milestone Jun 6, 2015
@Glavin001
Copy link
Owner

Upon reflection I think this is something that should be handled inside of Atom. Unfortunately, I am not sure how they will accomplish this, however I suggest that their setText function on the TextEditor somehow diffs the input from the current text state and knows how to properly setup the folds in relatively the same state as before.

I hope that this is something they will support in the future.

@Glavin001 Glavin001 reopened this Aug 19, 2015
@RiCoTeRoX
Copy link

something like that occurs with linter-jscs :(

@Szandor72
Copy link

Is there a little update on this? Constantly folding/unfolding does not make a lot of fun.

@teeramusic
Copy link

I would find this feature greatly useful as well.

@dlewand691
Copy link

Dear God, yes please. Have this feature would be a big time saver.

@Glavin001
Copy link
Owner

It looks like Atom now supports setTextViaDiff: https://atom.io/docs/api/v1.17.2/TextBuffer#instance-setTextViaDiff

Replace the current buffer contents by applying a diff based on the given text.

This would be our best shot to get this to work -- let Atom deal with the changing of the text and state of the folds.

This would require changing

editor.setText text
and testing it out.

Pull Requests very welcome!!

@Glavin001
Copy link
Owner

Original (un-beautified)

<!doctype html>
<html>

  <head>
    <title>Test Page</title>
  </head>

  <body>
    <h1>Hello</h1><p>
      World!
    </p>
  </body>

</html>

image

Before (with folds)

image

After

Current Version (setText)

image

Next Version (setTextViaDiff)

It worked! All folds are preserved.

image

And if I manually unfold:

image

Looks good!

@Glavin001
Copy link
Owner

Published to v0.29.26

@toddbluhm
Copy link
Author

@Glavin001 Thanks so much! This is awesome! And thanks for not letting this issue die off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants