Open TimMakins opened 7 years ago
In issue #307 I give a pretty good example of how to do folding. In your case, it looks to me like you are resetting the fold value to 0
when clearing--which could be the problem. The default value of a fold is 1024
.
EDIT: it also looks like you're not resetting the FoldLevelFlags
?
Thanks for replying to my question. In your #307 example there is no mention of resetting the FoldLevelFlags either. How should I reset them? Some information on FoldLeveLflags in general would be very helpful for all of us, I am sure.
Kind Regards, Tim
Hi, I found that setting the FoldLevelFlags to 0 is the same thing as resetting the flag. Here's some C# code that I've been tinkering with.
private void AddFoldRegion(int StartLine,int EndLine,int CurrentLevel)
{
int Start = StartLine,End = EndLine;
if (StartLine > EndLine)
{
Start = EndLine;
End = StartLine;
}
TextEditor.Lines[Start].FoldLevelFlags = FoldLevelFlags.Header;
TextEditor.Lines[Start].FoldLevel = CurrentLevel;
for(int i = Start + 1;i < End;++i)
{
TextEditor.Lines[i].FoldLevel = TextEditor.Lines[Start].FoldLevel + 1;
TextEditor.Lines[i].FoldLevelFlags = FoldLevelFlags.White;
}
TextEditor.Lines[End].FoldLevel = TextEditor.Lines[Start].FoldLevel + 1;
}
private void RemoveFoldRegion(int StartLine,int EndLine,int CurrentLevel)
{
int Start = StartLine,End = EndLine;
if (StartLine > EndLine)
{
Start = EndLine;
End = StartLine;
}
TextEditor.Lines[Start].FoldLevelFlags = 0;
TextEditor.Lines[Start].FoldLevel = CurrentLevel;
for(int i = Start + 1;i < End;++i)
{
TextEditor.Lines[i].FoldLevel = TextEditor.Lines[Start].FoldLevel;
TextEditor.Lines[i].FoldLevelFlags = 0;
}
TextEditor.Lines[End].FoldLevel = TextEditor.Lines[Start].FoldLevel;
}
Hopefully, this will be of some help to you.
Hi, I found that setting the FoldLevelFlags to 0 is the same thing as resetting the flag. Here's some C# code that I've been tinkering with.
private void AddFoldRegion(int StartLine,int EndLine,int CurrentLevel) { int Start = StartLine,End = EndLine; if (StartLine > EndLine) { Start = EndLine; End = StartLine; } TextEditor.Lines[Start].FoldLevelFlags = FoldLevelFlags.Header; TextEditor.Lines[Start].FoldLevel = CurrentLevel; for(int i = Start + 1;i < End;++i) { TextEditor.Lines[i].FoldLevel = TextEditor.Lines[Start].FoldLevel + 1; TextEditor.Lines[i].FoldLevelFlags = FoldLevelFlags.White; } TextEditor.Lines[End].FoldLevel = TextEditor.Lines[Start].FoldLevel + 1; } private void RemoveFoldRegion(int StartLine,int EndLine,int CurrentLevel) { int Start = StartLine,End = EndLine; if (StartLine > EndLine) { Start = EndLine; End = StartLine; } TextEditor.Lines[Start].FoldLevelFlags = 0; TextEditor.Lines[Start].FoldLevel = CurrentLevel; for(int i = Start + 1;i < End;++i) { TextEditor.Lines[i].FoldLevel = TextEditor.Lines[Start].FoldLevel; TextEditor.Lines[i].FoldLevelFlags = 0; } TextEditor.Lines[End].FoldLevel = TextEditor.Lines[Start].FoldLevel; }
Hopefully, this will be of some help to you.
Well it was very much helpful to me. :) I implemented Alt+0 to fold all lines just like in notepad++. Thanks Miki for your piece of code.
I am trying to write a minimum example of Scintilla folding. The program has a form with 2 textboxes that supply integers for the line number to start folding, and the number of lines to fold. There are also 2 buttons: 'Add Folding' that initiates the folding, and 'Clear Folding' that removes that folding. The 'Add Folding' works fine, and lets me add a number of small folds, but the 'Clear Folding' seems to clog the system up after a few attempts, and does not always show the folding line descenders when adding folding a second time. I assume that I am trying to clear my folding in the wrong way, but much searching has not shown me how I should be doing it. I would therefore be very grateful if you could point out my errors:
`Imports ScintillaNET Public Class Form1
End Class`