Browse Source

HiddenDef - Replace while(true) with do...while

pull/15/head
Eusebiu Marcu 15 years ago
parent
commit
2894998e5a
  1. 37
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs

37
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/HiddenDefinition/HiddenDefinitionRenderer.cs

@ -58,30 +58,37 @@ namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition
popup.IsOpen = true; popup.IsOpen = true;
} }
/// <summary>
/// Gets the line text near the offset.
/// </summary>
/// <param name="offset">Offset.</param>
/// <returns></returns>
private string GetLineText(int offset) private string GetLineText(int offset)
{ {
if (!editor.TextArea.TextView.VisualLinesValid)
return null;
// get line // get line
var line = editor.Document.GetLineByOffset(offset); var documentLine = editor.Document.GetLineByOffset(offset);
string text = editor.Document.Text; string documentText = editor.Document.Text;
string lineText = string.Empty;
int off, length;
while (true) { do {
if (line == null || line.IsDeleted) return null; if (documentLine == null || documentLine.IsDeleted) return null;
string lineString = text.Substring(line.Offset, line.Length).Trim(); off = documentLine.Offset;
length = documentLine.Length;
lineText = documentText.Substring(off, length).Trim();
if (lineString != "{" && !string.IsNullOrEmpty(lineString) && documentLine = documentLine.PreviousLine;
!lineString.StartsWith("//") && !lineString.StartsWith("/*") &&
!lineString.StartsWith("*") && !lineString.StartsWith("'"))
break;
line = line.PreviousLine;
} }
while (lineText == "{" || string.IsNullOrEmpty(lineText) ||
if (!editor.TextArea.TextView.VisualLinesValid) lineText.StartsWith("//") || lineText.StartsWith("/*") ||
return null; lineText.StartsWith("*") || lineText.StartsWith("'"));
// check whether the line is visible // check whether the line is visible
int off = line.Offset;
if (editor.TextArea.TextView.VisualLines[0].StartOffset > off) { 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; return null;

Loading…
Cancel
Save