This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 226482 - Code automatically folds when Pasted
Summary: Code automatically folds when Pasted
Status: RESOLVED WONTFIX
Alias: None
Product: editor
Classification: Unclassified
Component: Code folding (show other bugs)
Version: 7.3.1
Hardware: PC All
: P3 normal with 3 votes (vote)
Assignee: Svata Dedic
URL:
Keywords: UI
Depends on:
Blocks:
 
Reported: 2013-02-21 21:23 UTC by wnjordan
Modified: 2016-07-07 07:26 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (333.60 KB, text/plain)
2013-02-21 21:23 UTC, wnjordan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wnjordan 2013-02-21 21:23:32 UTC
Product Version = NetBeans IDE 7.3 RC2 (Build 201302050851)
Operating System = Linux version 3.2.0-37-generic-pae running on i386
Java; VM; Vendor = 1.7.0_09
Runtime = Java HotSpot(TM) Client VM 23.5-b02

When I copy code and paste it someplace, the IDE automatically folds everything in the pasted code block that is foldable.  The IDE appears to do this while ignoring the rules setup in 'Collapse by Default:'.

My suggestion would be to either not collapse the pasted code at all, or collapse it based on the rules established in  'Collapse by Default:'.
Comment 1 wnjordan 2013-02-21 21:23:35 UTC
Created attachment 131697 [details]
IDE log
Comment 2 Svata Dedic 2013-02-22 07:55:10 UTC
What file type is that ?
Comment 3 wnjordan 2013-02-22 18:50:18 UTC
I see this occurring in php, js and css files.  It seems to me like this is happening with all file types and is not type specific.  I might be specific to the php build of Netbeans though??
Comment 4 Svata Dedic 2013-02-22 22:37:35 UTC
Petre - this is the issue we were discussing over email a few weeks ago. The autofold feature does not apply just when the editor is opened, but to code that appears as new (its folds are created anew).

The processing algorithm can be changed if needed, even easier in > 7.3, since I'm going to centralize the 'folded' state assignment.

Please advise & reassing back.
Comment 5 Svata Dedic 2013-02-22 22:41:56 UTC
BTW i tried to copy/paste around some rule blocks in CSS, and they remained unfolded; could you please describe exact procedure, perhaps paste (a fragment of) the file where the issue happens ?
Also please describe your fold settings, or attach (zipped) $userdir/config, so I can extract the settings. Thanks.
Comment 6 Petr Somol 2013-02-26 12:24:43 UTC
(In reply to comment #4)
> Petre - this is the issue we were discussing over email a few weeks ago. The
> autofold feature does not apply just when the editor is opened, but to code
> that appears as new (its folds are created anew).
> 
> The processing algorithm can be changed if needed, even easier in > 7.3, since
> I'm going to centralize the 'folded' state assignment.
> 
> Please advise & reassing back.

The two acceptable types of behavior are exactly those as described in the original description of this issue: on paste or code insert either do not collapse at all, or do collapse according to rules set in options. I incline to recommend not to collapse on paste or code insert - the reason is this: on paste or insert the user is actively concerned with the piece of code in question and is likely to be interested in the outcome of the paste/insert action, so the resulting text would better be displayed in full. The idea of folding is helpful in quite a different situation - to reduce visual clutter, i.e., hide code that is likely to be currently not of interest for the user. Pasted/inserted code, however, is of immediate interest.
Comment 7 Svata Dedic 2013-02-26 12:28:26 UTC
Can you provide a counter-example when a fresh/copied code appears in an already opened editor window and should be auto-folded ?
Comment 8 wnjordan 2013-03-18 19:30:04 UTC
A counter example might be pasting a complete function or class into an existing script or perhaps pasting in code that is >X lines long. 

However, for every example I can think of, it's still better if the newly pasted code does not auto-collapse because when a developer pastes the new code they are most likely planning to work with it immediately.

One solution would be to create a new Code Folding Option that allows the developer to decide if they want pasted code to auto-collapse based on the other Code Folding rules.  That could be set to OFF by default.
Comment 9 janise 2013-09-11 17:47:42 UTC
This is exactly the problem I'm having too. I completely agree to Petr about not folding pasted code at all.

Another example is that I'm pasting just a part of a some function, maybe some part that is not collapsable by itself, but after it's pasted, the result text accidentally contains a block that is collapsable. The result after the paste might even contain a syntax error: I expect it and I know that after I paste these lines, I'll have to delete this and adjust that, but instead all or part of the code vanishes and I lose the eye-contact with the corresponding lines to be changed and have to expand and find the lines again. :)

If this auto-collapsing after paste is going to depend on some configuration options, please, make them separate from the already existing "Collapse by Default" options, because I want to collapse, say, methods upon opening a file, but I do not want to collapse anything when pasting code.
Comment 10 stuart_d 2014-10-13 07:47:46 UTC
We are up to version 8.0.1 and this bug is still not fixed. C'mon guys! It is an easily reproducible bug and an obvious annoyance for people who use auto-folding. 

Perhaps its not getting as much attention because its listed as a Linux bug, but I can confirm it is the same on Windows because that is what I'm using (in my case, 7 x64). No doubt, the other platforms are no exception.

Please, please fix the bug if you can! :)
Comment 11 wnjordan 2014-10-13 19:13:26 UTC
Code folding is absolutely abysmal in Netbeans.  Folds constantly unfold themselves, pages do not remember the folds when they've been closed then re-opened, the IDE is forever getting confused and turning code folding off if a page has been open too long or modified too much, pasting in new code has a tendency to unfold everything, there is no way to fold just the functions/methods and I'm sure I'm forgetting some of how bad it is.  The worst part is that the development team is not being given the resources to correct the problems.

Having said that, code folding is pretty much the only thing about Netbeans that isn't awesome.  The IDE on the whole is absolutely amazing.  I've tried phpStorm ($$) and it's code folding works perfectly. However, that IDE doesn't support multiple projects in the same window, which to me, is a far worse drawback than useless code folding.  The Netbeans IDE has so many amazing features that work great like css preprocessing, grunt integration, multiple repository support, built in ftp client, integrated terminal, integrated database tools and so many other features that all work great.  With everything it does well, it's really strange that code folding is where they dropped the ball.

Based on other threads related to the broken code folding, there appears to be only one way to fix the problem.  The after-thought, hacked in code folding system that exists today needs to be completely removed and replaced with a purpose built code folding system, based on the functionality of IDE's like phpStorm and NuSphere phpED.

Until Oracle decides to dedicate the resources necessary rebuild this feature we aren't really going to see things get better.  I might be wrong, but that's pretty much what it looks like from reading other threads and the fact that it's been a persistent problem for a very long time that, if anything, has gotten worse instead of better.

I've made the following attribute changes to this bug:
Version: 8.0.1 - since it's still an problem.
Hardware: PC->All - based on start_d's comment.
Comment 12 wnjordan 2014-10-13 19:30:58 UTC
I just received an email that Marian Mirilovic <mmirilovic@netbeans.org> changed the Version back to 7.3.1.  This bug is as relevant for for 8.0.1 as it was for 7.3.1.  Why did you change it back?
Comment 13 MackSix 2014-10-14 03:46:49 UTC
(In reply to wnjordan from comment #12)
> I just received an email that Marian Mirilovic <mmirilovic@netbeans.org>
> changed the Version back to 7.3.1.  This bug is as relevant for for 8.0.1 as
> it was for 7.3.1.  Why did you change it back?


The NetBeans version is to be left at the original version it was reported under. Bugs are always considered to be valid in the original reported version and all following versions unless the bug status is RESOLVED. When it is resolved, the comments will indicate the version it was resolved in.
Comment 14 Svata Dedic 2014-10-14 06:47:28 UTC
Hi,

(In reply to wnjordan from comment #11)
> Code folding is absolutely abysmal in Netbeans.  Folds constantly unfold
> themselves, pages do not remember the folds when they've been closed then

it's pretty hard (or error-prone) to identify all bad behaviours in your comment and properly track them so they can get eventually resolved or connected with other bug report. Would you be so kind and turn each annoying behaviour into a defect/enhancement ? I'll link them with the possible related defects and we may work toward a reproduction case for each of them (which is usually the main problem with code folding), and finally to resolution.

Also please note that 'code folding' is a joint effort of the base infrastructure (visual marks, data structures, update scheduling) and individual language providers. Some bugs you may encounter can be a result of inadequate infrastructure, some of them may be tracked down to language provider. Unlike the editors you mentioned, the common infrastructure has to be language-neutral.

> The after-thought, hacked in code folding
> system that exists today needs to be completely removed
I would like to see a code and API analysis what is 'afterthought' and 'hacked'. There are usually reasons why the implementation or API is designed that way, and a fresh input could raise the correct questions about those reasons :) It would also allow others to better contribute, or me to be more effective when I can allocate my time to NB bug fixing - thanks !


BTW - there's a way how to fold a function; I believe PHP allows to do so. Manual folds can be specified by XML-like content in a comment:
// <editor-fold collapsed="true">
...
// </editor-fold>
(it may not be what you'd like, but it's there and can be used, if it +- fits).

There's for example an enhancement request demanding that folds are remembered even if the editor is closed but not voted enough - so not implemented. Etc. If we sort and categorize your (and others') ideas, areas that need focus may become more visible.
Comment 15 stuart_d 2014-10-14 15:58:30 UTC
I forgot to mention in my comment that in my case, I was coding in Java (on Windows).

I am fairly confident the bug should be reproducible because I just tested it again after resetting to default settings (I couldn't see a built-in way to do this but deleting the "8.0.1" folder under "Roaming\NetBeans" seemed to do the trick).

Then I ran NB, opened Options > Editor > Folding and ticked the 'Member' checkbox (All Languages). That is the only adjustment I made.

I then created a new Java project selecting one of the samples ("GUI Form Examples"), copy/pasted one of the methods in the code and sure enough, it auto-folds.

I can upload an export of the settings if necessary though I can't imagine why given I only changed one setting.
Comment 16 Martin Balin 2016-07-07 07:26:55 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss