Skip to content

Save expand/collapse code folding! #3441

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

Closed
MrKp91 opened this issue Jun 30, 2015 · 9 comments
Closed

Save expand/collapse code folding! #3441

MrKp91 opened this issue Jun 30, 2015 · 9 comments
Labels
Component: IDE user interface The Arduino IDE's user interface

Comments

@MrKp91
Copy link

MrKp91 commented Jun 30, 2015

I've recently found under preference the ability to have code folding which is very helpful but every time I switch tabs everything is expanded.

This is very annoying specially when you have collapse specific parts of your code and go check something on another tab just to have it all expanded.

ALSO, it would be nice if there's a shortcut to collapse/expand everything.

Thanks!

@ffissore
Copy link
Contributor

ffissore commented Jul 1, 2015

That will take a while to get solved. The root cause is that we use the same editor for every tab, replacing its content every time your switch one. This resets its previous settings, like folded code blocks.
This is a legacy behaviour, which forced us event to code a customized version of the new editor (RSyntaxTextArea)
Solution is to stop recycling the editor and create new ones for each tab. Once done, this issue should autosolve

@ffissore ffissore added the Component: IDE user interface The Arduino IDE's user interface label Jul 1, 2015
@ffissore ffissore self-assigned this Jul 1, 2015
@lmihalkovic
Copy link

This is another example of a very low hanging fruits in this project (just added the feature to my branch despite still doing editor sharing and it works fine), and blaming the editor-sharing is just a bad excuse for not implementing the feature.

There are fundamentally no technical justification for the customized version of RSTxtArea, and this one owes more to poorly structured code than to real requirements. That is one of the issues plaguing this industry: "It can't be done" used liberally in place of "I don't know how to do it".

@lmihalkovic
Copy link

just in case... this is to prove that it is indeed extremely simple to implement:

  @Override
  protected void configureFolding(SketchFileType type) {
    textarea.setCodeFoldingEnabled(true);
    textarea.getFoldManager().addPropertyChangeListener(new PropertyChangeListener() {      
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
        if(evt.getPropertyName() == FoldManager.PROPERTY_FOLDS_UPDATED) {
          @SuppressWarnings("unchecked")
          List<Fold> list = (List<Fold>)evt.getNewValue();
          state().foldings = list;
        }        
      }
    });
  }  

  @Override
  public void restoreState() {
    List<Fold> list = state().foldings;
    textarea.getFoldManager().setFolds(list);
  }  

@lmihalkovic
Copy link

@cmaglie @matthijskooijman should you have the availability within the near future, it would likely be very appreciated if you'd look into this one. The code does work as-is in my fork, but will need some adapting for your codebase. I gave a short description of what it boils down to here, there is really nothing more to it. (oops.. and yes, surprisingly it works despite the very stupid == which I will fix).

matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 30, 2015
RSyntaxTextArea appears to support using a single instance and replacing
the underlying text and document when switching between tabs, but in
practice this support is not complete and even though the
RSyntaxTextArea developers did some work to improve the situation, they
recommend to just use a seperate instance for each tab.

This commit implements exactly that. A new class EditorTab is introduce
to wrap the RSyntaxTextArea and containing scroll pane, and to
encapsulate the code related to handling the text area itself. Doing so
removes some quirks and prepares for some later additions. In
particular, error highlights are now no longer shared between all tabs,
which was previously the case.

This commit mostly moves code from Editor into EditorTab, and updates
the callers to use getCurrentTab() and call methods on the result
instead of calling them on Editor. Some code is added to take care of
creating multiple EditorTab objects and switching between them. Some
small changes have been made to make the flow of opening files work,
though these are mostly a bit hacky.

While moving code, changes to the rest of the code were kept minimal,
retaining existing interfaces as much as possible. This sometimes result
in less than ideal code, which should be cleaned up in subsequent
commits.

The SketchCodeDocument class has been pretty much emptied out, since
it was mostly used to store things for tabs in the background, which are
now just stored in each RSyntaxTextArea separately. The last remaining
bits of this class can probably be moved or implemented differently
later, so it can be removed.

The entire flow of working with sketches and files needs to be cleaned
up next, so no thorough attempt at testing this commit was done. It is
likely that there are plenty of corner cases and race conditions, which
will be fixed once the reset of the code is cleaned up.

Fixes arduino#3441
@matthijskooijman
Copy link
Collaborator

@lmihalkovic your fix seems good to me, with the current code. However, in #4363 I opted for a different fix: Keep a different RSyntaxTexArea for each tab. Even though RSyntaxTextArea seems to support switching between multiple documents (and some improvements were made in this area), but in the end the author still somewhat recommends just using a separate instance for each tab. I recalled that there was a more explicit recommendation than the one I mentioned above, but I could not find it just now.

@lmihalkovic
Copy link

@matthijskooijman the code is and always was irrelevant. I only shared it to prove how utterly wrong the initial evaluation of the severity of the problem/complication of the solution were. Fixing this issue is and always was a trivial matter which should have only taken 20 minutes the days this ticket was created.

This was my point... i have watched this repo for 2 months now, and I am truly surprised by the number of issues where similarly wrong assessments exist to justify not addressing issues that should have taken, in many instances, at best a couple days of a programmer's time.

And IMHO #4363 goes one step further by destroying useful flexible constructs only to replace them with an equally arbitrary, but IMHO less practical, choice of entanglement. But i fully appreciate that it will take you a number of days/months/years (looking at a number of things i saw, i would wager that you have not written much java code yet) before we can even have a meaningful debate on the topic.

matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Jan 21, 2016
RSyntaxTextArea appears to support using a single instance and replacing
the underlying text and document when switching between tabs, but in
practice this support is not complete and even though the
RSyntaxTextArea developers did some work to improve the situation, they
recommend to just use a seperate instance for each tab.

This commit implements exactly that. A new class EditorTab is introduce
to wrap the RSyntaxTextArea and containing scroll pane, and to
encapsulate the code related to handling the text area itself. Doing so
removes some quirks and prepares for some later additions. In
particular, error highlights are now no longer shared between all tabs,
which was previously the case.

This commit mostly moves code from Editor into EditorTab, and updates
the callers to use getCurrentTab() and call methods on the result
instead of calling them on Editor. Some code is added to take care of
creating multiple EditorTab objects and switching between them. Some
small changes have been made to make the flow of opening files work,
though these are mostly a bit hacky.

While moving code, changes to the rest of the code were kept minimal,
retaining existing interfaces as much as possible. This sometimes result
in less than ideal code, which should be cleaned up in subsequent
commits.

The SketchCodeDocument class has been pretty much emptied out, since
it was mostly used to store things for tabs in the background, which are
now just stored in each RSyntaxTextArea separately. The last remaining
bits of this class can probably be moved or implemented differently
later, so it can be removed.

The entire flow of working with sketches and files needs to be cleaned
up next, so no thorough attempt at testing this commit was done. It is
likely that there are plenty of corner cases and race conditions, which
will be fixed once the reset of the code is cleaned up.

Fixes arduino#3441
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Jan 21, 2016
RSyntaxTextArea appears to support using a single instance and replacing
the underlying text and document when switching between tabs, but in
practice this support is not complete and even though the
RSyntaxTextArea developers did some work to improve the situation, they
recommend to just use a seperate instance for each tab.

This commit implements exactly that. A new class EditorTab is introduce
to wrap the RSyntaxTextArea and containing scroll pane, and to
encapsulate the code related to handling the text area itself. Doing so
removes some quirks and prepares for some later additions. In
particular, error highlights are now no longer shared between all tabs,
which was previously the case.

This commit mostly moves code from Editor into EditorTab, and updates
the callers to use getCurrentTab() and call methods on the result
instead of calling them on Editor. Some code is added to take care of
creating multiple EditorTab objects and switching between them. Some
small changes have been made to make the flow of opening files work,
though these are mostly a bit hacky.

While moving code, changes to the rest of the code were kept minimal,
retaining existing interfaces as much as possible. This sometimes result
in less than ideal code, which should be cleaned up in subsequent
commits.

The SketchCodeDocument class has been pretty much emptied out, since
it was mostly used to store things for tabs in the background, which are
now just stored in each RSyntaxTextArea separately. The last remaining
bits of this class can probably be moved or implemented differently
later, so it can be removed.

The entire flow of working with sketches and files needs to be cleaned
up next, so no thorough attempt at testing this commit was done. It is
likely that there are plenty of corner cases and race conditions, which
will be fixed once the reset of the code is cleaned up.

Fixes arduino#3441
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue Apr 27, 2016
RSyntaxTextArea appears to support using a single instance and replacing
the underlying text and document when switching between tabs, but in
practice this support is not complete and even though the
RSyntaxTextArea developers did some work to improve the situation, they
recommend to just use a seperate instance for each tab.

This commit implements exactly that. A new class EditorTab is introduce
to wrap the RSyntaxTextArea and containing scroll pane, and to
encapsulate the code related to handling the text area itself. Doing so
removes some quirks and prepares for some later additions. In
particular, error highlights are now no longer shared between all tabs,
which was previously the case.

This commit mostly moves code from Editor into EditorTab, and updates
the callers to use getCurrentTab() and call methods on the result
instead of calling them on Editor. Some code is added to take care of
creating multiple EditorTab objects and switching between them. Some
small changes have been made to make the flow of opening files work,
though these are mostly a bit hacky.

While moving code, changes to the rest of the code were kept minimal,
retaining existing interfaces as much as possible. This sometimes result
in less than ideal code, which should be cleaned up in subsequent
commits.

The SketchCodeDocument class has been pretty much emptied out, since
it was mostly used to store things for tabs in the background, which are
now just stored in each RSyntaxTextArea separately. The last remaining
bits of this class can probably be moved or implemented differently
later, so it can be removed.

The entire flow of working with sketches and files needs to be cleaned
up next, so no thorough attempt at testing this commit was done. It is
likely that there are plenty of corner cases and race conditions, which
will be fixed once the reset of the code is cleaned up.

Fixes arduino#3441
@Jim4Beam
Copy link

Is there a work arround or solution for the ode folding issue yet? Sorry I am new to programmig.

@matthijskooijman
Copy link
Collaborator

@Jim4Beam, AFAIU the PR that fixes this is scheduled to be fixed shortly after the next Arduino release.

cmaglie pushed a commit to cmaglie/Arduino that referenced this issue Aug 13, 2016
RSyntaxTextArea appears to support using a single instance and replacing
the underlying text and document when switching between tabs, but in
practice this support is not complete and even though the
RSyntaxTextArea developers did some work to improve the situation, they
recommend to just use a seperate instance for each tab.

This commit implements exactly that. A new class EditorTab is introduce
to wrap the RSyntaxTextArea and containing scroll pane, and to
encapsulate the code related to handling the text area itself. Doing so
removes some quirks and prepares for some later additions. In
particular, error highlights are now no longer shared between all tabs,
which was previously the case.

This commit mostly moves code from Editor into EditorTab, and updates
the callers to use getCurrentTab() and call methods on the result
instead of calling them on Editor. Some code is added to take care of
creating multiple EditorTab objects and switching between them. Some
small changes have been made to make the flow of opening files work,
though these are mostly a bit hacky.

While moving code, changes to the rest of the code were kept minimal,
retaining existing interfaces as much as possible. This sometimes result
in less than ideal code, which should be cleaned up in subsequent
commits.

The SketchCodeDocument class has been pretty much emptied out, since
it was mostly used to store things for tabs in the background, which are
now just stored in each RSyntaxTextArea separately. The last remaining
bits of this class can probably be moved or implemented differently
later, so it can be removed.

The entire flow of working with sketches and files needs to be cleaned
up next, so no thorough attempt at testing this commit was done. It is
likely that there are plenty of corner cases and race conditions, which
will be fixed once the reset of the code is cleaned up.

Fixes arduino#3441
@TehseenHasan
Copy link

any solution for code folding as this issue stated in the title?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE user interface The Arduino IDE's user interface
Projects
None yet
Development

No branches or pull requests

6 participants