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 @@ -58,30 +58,37 @@ namespace ICSharpCode.AvalonEdit.AddIn.HiddenDefinition
popup.IsOpen = true;
}
/// <summary>
/// Gets the line text near the offset.
/// </summary>
/// <param name="offset">Offset.</param>
/// <returns></returns>
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;

Loading…
Cancel
Save