How to disable Eclipse's "auto-folding during typing"?
Asked Answered
P

1

8

Eclipse (any version AFAIK) has some weird behavior related to folding in Java code. Suppose I’m editing this class:

class A {
  String field;
  @Nonnull 
  Object method(){
    // whatever
  }
}

If folding is enabled and I tell it to collapse everything (it’s Control-NumSlash in mine, but that might be customized), the method is correctly folded, i.e. it shows only Object method()... for the method. All good ’till now.

The part that bothers me is that if I move the cursor right after field;, press Enter, and type something like “public”, and then stop for a second, Eclipse automatically folds that word into the method below.

That might seem reasonable (presumably it assumes I wanted to add that qualifier to the method); but in practice what I’m actually doing is trying to add a new method, and paused for a moment to think about its return type or maybe its name. (If I wanted to modify the method I’d unfold it first, since it might already have that qualifier, folded.)

I hate this “feature” with passion, but I can’t for the life of me find out how to disable it, nor even which of the damned mess of plugins (that Eclipse keeps insisting I should not be allowed to remove) is responsible for it so I can file a bug report.

So, does anyone know (1) where does that behavior come from, and hopefully (2) how can I get rid of it but keep manual folding? Thanks!

(For the record, I’m using Kepler SR1, but this behavior goes back a really long time, at least five years or so.)

Pacify answered 7/3, 2014 at 10:55 Comment(0)
C
2

I don't believe there's any way to prevent it from doing that unless you just make a habit of putting a semicolon ; or closing curly brace } after public which prevents the Object method(){.. from 'folding' it up. I believe it's written to fold everything up until the closest semicolon which is why @Nonnull is also included.

The only options for folding I can find are located in Window > Preferences > Java > Editor > folding

I would consider this to be a bug, or just a feature that had unintended side effects.

Funny enough, if you put almost any symbol or misspell public it wont fold it.

Cherin answered 31/3, 2014 at 21:41 Comment(3)
Good point about typing a symbol, thank you. Parentheses work as well. I might try that until I have the time to figure out how to submit a patch.Pacify
This behaviour still distracts a lot when writing. Even 7 years later I only find this answer addressing the problem, and the solution to write code in a way the IDE likes it is bad DX. Is there no better solution?Alex
@Alex If it's been bothering you for 7 years, why haven't you proposed a patch yet? Probably most (including me) have never faced this issue, because they do not use Collapse All or use the content assist to create a method (e.g. typing pub and then, without taking a nap, hitting Ctrl+Space; the open content assist prevents to get something hidden). And even if it happened to me, I would just hit Ctrl+Q (or Ctrl+Alt+Left) to go back to the last edit location.Conics

© 2022 - 2024 — McMap. All rights reserved.