diff --git a/ILSpy/TextView/AvalonEditTextOutput.cs b/ILSpy/TextView/AvalonEditTextOutput.cs index 4ea8afa17..f74ed01d7 100644 --- a/ILSpy/TextView/AvalonEditTextOutput.cs +++ b/ILSpy/TextView/AvalonEditTextOutput.cs @@ -99,7 +99,7 @@ namespace ICSharpCode.ILSpy.TextView TextSegmentCollection references = new TextSegmentCollection(); /// Stack of the fold markers that are open but not closed yet - Stack openFoldings = new Stack(); + Stack<(NewFolding, int startLine)> openFoldings = new Stack<(NewFolding, int startLine)>(); /// List of all foldings that were written to the output internal readonly List Foldings = new List(); @@ -315,19 +315,20 @@ namespace ICSharpCode.ILSpy.TextView public void MarkFoldStart(string collapsedText = "...", bool defaultCollapsed = false) { WriteIndent(); - openFoldings.Push( + openFoldings.Push(( new NewFolding { StartOffset = this.TextLength, Name = collapsedText, DefaultClosed = defaultCollapsed - }); + }, lineNumber)); } public void MarkFoldEnd() { - NewFolding f = openFoldings.Pop(); + var (f, startLine) = openFoldings.Pop(); f.EndOffset = this.TextLength; - this.Foldings.Add(f); + if (startLine != lineNumber) + this.Foldings.Add(f); } public void AddUIElement(Func element)