In our Scintilla based editor, we support folding of consecutive comment lines, i.e. lines that only consists of line comments, e.g.:
// line 1
// line 2
This means that two separate blocks can be merged by either deleting the separating line or by making the separating line a line comment as well:
// line 1 of block 1
// line 2 of block 1
// line 1 of block 2
// line 2 of block 2
If the two blocks are collapsed, Scintilla by default doesn't handle the merging correctly regarding the fold state: the two blocks need to be expanded. The attached patch implements this behaviour in Editor::FoldChanged().
Starting with this C document:
where structure 'a' is collapsed, the patch will expand 'a' when the '{' after 'c' is removed.
The attached patch fixes this. The previous block may only be expanded if the fold levels are the same.
Its the second hunk in the patch that triggers for the "adding characters in the line" case such as when using Perl in SciTE with fold.compact=0 and this document when a '#' is added to line 3:
Is there an example that triggers the FoldLine in hunk 1?
Are there any circumstyances in which FoldLines in the patch should collapse? If not then SC_FOLDACTION_EXPAND should be used instead of SC_FOLDACTION_TOGGLE.
Scintilla must still build with with C++03 so auto for declarations is not possible.
My bad: I mixed up the two comments.
The new patch fixes the comments and states the cases more precisely. I added one more comment that handles the case "Combining two blocks where the second one is collapsed". I also replaced the auto keyword with the data types.
Yes, the folds should always expand, never collapse.
BTW: what's the difference between Editor::FoldLine(line, SC_FOLDACTION_EXPAND) and Editor::FoldExpand(line, SC_FOLDACTION_EXPAND, level)?
I haven't found a case where this breaks but I suspect this line needs to mask the levels with SC_FOLDLEVELNUMBERMASK:
may change to
Last edit: Neil Hodgson 2016-01-22
Yes, your suggestion will be safer as from a logical point of view, we only want to compare the depth of folding, not taking into account any additional flags.
Fix committed as [def6d8]. SciTE version in [21ad2b].
Related
Commit: [21ad2b]
Commit: [def6d8]
There are problems with this change mentioned in [#1896]. Making this change more selective may avoid it failing as described.
Related
Bugs:
#1896