Currently, to fold the current block (F12) I have to position the cursor in the first row of the block and then press F12 or click the fold button.
This is not practical, since CB already knows which block the line belongs to.
The best would be CB fold the block relative to the line where the cursor is, which is more intuitive
This patch fixes the behaviour. I honestly don't know the reason behind the check... I think it is legal to always fold the line. Some explanatory comment would be nice...
bluehazzard: Have you done some more thorough testing of this patch? For me f12 doesn't work if the files starts with:
and I try to fold/unfold at line 2 (the open curly brace).
Ok, i looked again into this, and codeblocks complicates things quite a bit. I do not want to touch all the functions, because i do not know what consequences this has (for example the toggle all folding function is wired...)
I attach a better patch, but it is still strange.... For example if you have the following code:
If you fold (by pressing F12, what has the meaning toggle) it on point (1) first, and then press F12 again on point (2) it will unfold all. This is not really the expected behaviour, isn't it?
And this goes on for all folding operations... It is consistent, (by toggling all blocks) but not intuitive.
My proposed solution is in patch v3: Always toggle only the current Block:
If you press F12 on point (1) it will fold the inner if. After that if you press F12 on Point (2) it will fold the main function. And in the unfold direction it is the same.
I am not quite sure about the unfolding code. I Think it is used if you want to unfold text that is folded, not by cursor, but by scripting. I can not test this, because i can not use the derived cbEditor class functions, only the cbEditorBase function in scripting. No idea why this does not work...
Last edit: bluehazzard 2018-09-11
The original code is quite complex and odd. I think either scintilla had awkward api back when this was first written or someone didn't understood how the api works. I'll prepare a simpler patch, soon... And then we'll fix the features I've accidentally removed. :)
This is also funny:
I was thinking this code is intentional as complicated as it is. Because for example if you toggle all folding in scintilla it only looks at the first possible folding line and then folds the rest of the document like the first line. The code in codeblocks makes a real toggle, line for line... If this is good or bad, i don't know. It is complicated...
What do you mean by toggle all in scintilla? I've almost finished cleaning up this code. I'll post a patch for testing soon.
https://www.scintilla.org/ScintillaDoc.html#SCI_FOLDALL
Here is a branch [1] with fixes for both this issue and fold all.
Testing is appreciated.
[1] https://github.com/obfuscated/codeblocks_sf/tree/experiments/folding
Topic where you could post feedback is here: http://forums.codeblocks.org/index.php/topic,22821.0.html
In trunk, thanks for reporting, let us know if you find more problems.