Skip to content

Commit

Permalink
Automatically scroll code preview based on indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed May 30, 2015
1 parent 921f9ba commit ec4a7c7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Controls/CodePreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private void SetupEditor()
if (this.ZoomLevel != zoomLevel)
this.ZoomLevel = zoomLevel;
} */

this.Editor.SetProperty("lexer.cpp.track.preprocessor", "0");
}

private void UpdateFoldedCode()
Expand Down Expand Up @@ -120,10 +122,21 @@ public void CenterEditor(int line)

// Constrain the first visible line to a reasonable number
int firstVisibleLine = Math.Min(Math.Max(line - (int)Math.Floor(linesOnScreen / 2.0), 0), lineCount - linesOnScreen + 1);

// Calculate shift then scroll
int delta = firstVisibleLine - firstLine - 1;
this.Editor.LineScroll(0, delta);
this.Editor.LineScroll(-5000, delta);

firstLine = this.Editor.FirstVisibleLine;

var column = int.MaxValue;
for (var offset = 0; offset < this.Editor.LinesOnScreen; offset++)
{
var lineIndentation = this.Editor.GetLineIndentation(firstLine + offset);
column = Math.Min(column, this.Editor.GetLineIndentation(firstLine + offset));
}

this.Editor.LineScroll(column - 2, 0);
}
}
}

0 comments on commit ec4a7c7

Please sign in to comment.