From fe2d44880294770613c4a123498e27360da3cc62 Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Wed, 22 Nov 2017 22:12:01 +0100 Subject: [PATCH] Fix GenerateFoldMarkers --- Kaxaml/CodeCompletion/XmlFoldingStrategy.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Kaxaml/CodeCompletion/XmlFoldingStrategy.cs b/Kaxaml/CodeCompletion/XmlFoldingStrategy.cs index 5902a1a..e33bd9d 100644 --- a/Kaxaml/CodeCompletion/XmlFoldingStrategy.cs +++ b/Kaxaml/CodeCompletion/XmlFoldingStrategy.cs @@ -120,9 +120,9 @@ public List GenerateFoldMarkers(IDocument document, string fileName, { using (var reader = new XmlTextReader(stringReader)) { + var stack = new Stack(); while (reader.Read()) { - var stack = new Stack(); switch (reader.NodeType) { case XmlNodeType.Element: @@ -134,8 +134,11 @@ public List GenerateFoldMarkers(IDocument document, string fileName, break; case XmlNodeType.EndElement: - XmlFoldStart foldStart = (XmlFoldStart)stack.Pop(); - CreateElementFold(document, foldMarkers, reader, foldStart); + if (stack.Count > 0) + { + XmlFoldStart foldStart = (XmlFoldStart)stack.Pop(); + CreateElementFold(document, foldMarkers, reader, foldStart); + } break; case XmlNodeType.Comment: