Hi.
While the document you refer to, is probably the best document available in terms of current (Lazarus) SynEdit doc, it was written by observation. That is written by a user, not the maintainer of the code.
That still (or even more ) makes it a very good document. But it means the document may tend to describe the actual state (what currently is), rather than the intend (what should be).
What you describe is a bug, as in missing implementation.
The background is, that folding of selected text was written after all the other methods. And it turns out they do not work on it.
The difference is that the selection gets "hidden" rather than folded (Afaik, you can configure that, search FoldConfig, in the IDE folder).
Hiding means that all lines, including the very first, will be un-displayed.
Folding keeps the first line in view.
To fix this, you can edit SynEdit as follows (I will likely commit a similar fix sometime soon)
Find in SynEdit.pp line 3715 (SVN trunk / line may differ in 1.2) the function
TCustomSynEdit.CodeFoldAction
The very last "IF" in this function is
if FFoldedLinesView.FoldType[FFoldedLinesView.TextIndexToScreenLine(iLine)]
* [cfFoldStart] <> []
Replace [cfFoldStart]
with [cfFoldStart, cfHideStart]
The entire procedure will then look like (you changed the 4th line from the bottom):
procedure TCustomSynEdit.CodeFoldAction(iLine: integer);
// iLine is 1 based as parameter
begin
if (iLine<=0) or (iLine>FTheLinesView.Count) then exit;
dec(iLine);
//DebugLn(['****** FoldAction at ',iLine,' scrline=',FFoldedLinesView.TextIndexToScreenLine(iLine), ' type ', SynEditCodeFoldTypeNames[FFoldedLinesView.FoldType[FFoldedLinesView.TextIndexToScreenLine(iLine)]], ' view topline=',FFoldedLinesView.TopLine ]);
if FFoldedLinesView.FoldType[FFoldedLinesView.TextIndexToScreenLine(iLine)]
* [cfCollapsedFold, cfCollapsedHide] <> []
then
FFoldedLinesView.UnFoldAtTextIndex(iLine)
else
if FFoldedLinesView.FoldType[FFoldedLinesView.TextIndexToScreenLine(iLine)]
* [cfFoldStart, cfHideStart] <> []
then
FFoldedLinesView.FoldAtTextIndex(iLine);
end;
Then use
Editor.CodeFoldAction( Editor.BlockBegin.Y );
------------------
Editor.FoldAll
only works with primary folds form the code.
e.g If you use the Pascal Highlighter, it will fold Procedure, begin-end, class-end, ...
But it will not fold Ifdef, region, or selection. ifdef and region are secondary fold structures. (well there is no name for that, so I just call them secondary for now)
-------------------
EcFoldCurrent
will take some more time to fix.
In fact I am not sure if it is a good idea. It searches from the current line up (including on the current line) for the begin of a fold that include the current line.
That is, it searches the most inner fold, that includes the current line.
So if there was a selection, but a begin-end was closer to the caret, then it would still be begin end.
Maybe it can be made a configurable option.
And there should probably be
EcFoldSelection
You may want to report this on mantis, for I am not going to work on the EcFoldCurrent part right now, and it will get forgotten if there is no report,