From 2894998e5afd3a2f5005e6969be79e323ce3bb0b Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Thu, 30 Dec 2010 02:40:14 +0200 Subject: [PATCH] HiddenDef - Replace while(true) with do...while --- .../HiddenDefinitionRenderer.cs | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs index 77eb9584c2..498f673113 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs @@ -58,30 +58,37 @@ namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition popup.IsOpen = true; } + /// + /// Gets the line text near the offset. + /// + /// Offset. + /// private string GetLineText(int offset) { + if (!editor.TextArea.TextView.VisualLinesValid) + return null; + // get line - var line = editor.Document.GetLineByOffset(offset); - string text = editor.Document.Text; + var documentLine = editor.Document.GetLineByOffset(offset); + string documentText = editor.Document.Text; + string lineText = string.Empty; + int off, length; - while (true) { - if (line == null || line.IsDeleted) return null; - string lineString = text.Substring(line.Offset, line.Length).Trim(); + do { + if (documentLine == null || documentLine.IsDeleted) return null; + off = documentLine.Offset; + length = documentLine.Length; + lineText = documentText.Substring(off, length).Trim(); - if (lineString != "{" && !string.IsNullOrEmpty(lineString) && - !lineString.StartsWith("//") && !lineString.StartsWith("/*") && - !lineString.StartsWith("*") && !lineString.StartsWith("'")) - break; - line = line.PreviousLine; + documentLine = documentLine.PreviousLine; } - - if (!editor.TextArea.TextView.VisualLinesValid) - return null; + while (lineText == "{" || string.IsNullOrEmpty(lineText) || + lineText.StartsWith("//") || lineText.StartsWith("/*") || + lineText.StartsWith("*") || lineText.StartsWith("'")); // check whether the line is visible - int off = line.Offset; if (editor.TextArea.TextView.VisualLines[0].StartOffset > off) { - return this.editor.TextArea.TextView.Document.GetText(off, line.Length); + return this.editor.TextArea.TextView.Document.GetText(off, length); } return null;