thehogfather / brackets-code-folding

Code folding extension for brackets IDE
134 stars 42 forks source link

Code collapse gets stuck collapsed with Undo #67

Closed JeffryBooher closed 10 years ago

JeffryBooher commented 10 years ago
  1. Create a new js file
  2. Add the following code block:
 /**
   * Returns the thing
   * 
   */
function getTheThing() {
     var s = blah();
     return s.execute();
}

 /**
   * Returns more things
   * 
   */
function getMoreThings() {
     var s = blah();
     return s.execute();
}

3 . now wrap the block with /* */

You should end up with something like this:

/*
 /**
   * Returns the thing
   * 
   */
function getTheThing() {
     var s = blah();
     return s.execute();
}

 /**
   * Returns more things
   * 
   */
function getMoreThings() {
     var s = blah();
     return s.execute();
}
*/

you should get a collapse disclosure beside the topmost /*

4 . collapse the block 5 . undo

cannot expand the block

While trying to find the steps to this I was occasionally unable to reproduce this but i did get it to reproduce if I added the closing */ first then the opening comment /*, collapsed then undo so you might want to try it both ways.

thehogfather commented 10 years ago

Thanks that an interesting one - and very easy to reproduce. It is easy to see how the undo changes the state of the folding regions - and this issue goes right down into the code-mirror addon for folding. So, from a user point of view perhaps it make sense to automatically unfold folded regions that no longer exist? i.e., when you do an undo or delete the char that closes a fold region, if the region is folded, then it should be expanded.

JeffryBooher commented 10 years ago

That's what i was thinking as well but you could also ague that the outer /* */ is invalid and shouldn't be collapsible. Not sure if that solves the issue or not but something to think about.

thehogfather commented 10 years ago

Indeed because the concept of nesting is ubiquitous. e.g., nested functions, JS object literals etc. So it is even reproducible using:

function () {
function() {

}}

Collapse the outermost function and delete the last brace. For now I have a fix that auto expands the invalid range. I will push once I'm reasonably convinced it doesnt break anything else.