diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs
index 8c41151858..06734e8a62 100644
--- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs
+++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs
@@ -351,6 +351,9 @@ namespace ICSharpCode.TextEditor
int scrollMarginHeight = 3;
+ ///
+ /// Ensure that is visible.
+ ///
public void ScrollTo(int line)
{
line = Math.Max(0, Math.Min(Document.TotalNumberOfLines - 1, line));
@@ -377,6 +380,32 @@ namespace ICSharpCode.TextEditor
}
}
+ ///
+ /// Scroll so that the specified line is centered.
+ ///
+ /// Line to center view on
+ /// If this action would cause scrolling by less than or equal to
+ /// lines in any direction, don't scroll.
+ /// Use -1 to always center the view.
+ public void CenterViewOn(int line, int treshold)
+ {
+ line = Math.Max(0, Math.Min(Document.TotalNumberOfLines - 1, line));
+ // convert line to visible line:
+ line = Document.GetVisibleLine(line);
+ // subtract half the visible line count
+ line -= textArea.TextView.VisibleLineCount / 2;
+
+ int curLineMin = textArea.TextView.FirstPhysicalLine;
+ if (textArea.TextView.LineHeightRemainder > 0) {
+ curLineMin ++;
+ }
+ if (Math.Abs(curLineMin - line) > treshold) {
+ // scroll:
+ this.vScrollBar.Value = Math.Max(0, Math.Min(this.vScrollBar.Maximum, (line - scrollMarginHeight + 3) * textArea.TextView.FontHeight)) ;
+ VScrollBarValueChanged(this, EventArgs.Empty);
+ }
+ }
+
public void JumpTo(int line)
{
line = Math.Min(line, Document.TotalNumberOfLines - 1);
diff --git a/src/Main/Base/Project/Src/Services/File/FileService.cs b/src/Main/Base/Project/Src/Services/File/FileService.cs
index a8e093a964..881876613c 100644
--- a/src/Main/Base/Project/Src/Services/File/FileService.cs
+++ b/src/Main/Base/Project/Src/Services/File/FileService.cs
@@ -283,13 +283,6 @@ namespace ICSharpCode.SharpDevelop
}
}
- public static void OnJumpedToFilePosition(string fileName)
- {
- if (JumpedToFilePosition != null) {
- JumpedToFilePosition(null, new FileEventArgs(fileName, false));
- }
- }
-
public static event EventHandler FileRenaming;
public static event EventHandler FileRenamed;
@@ -298,7 +291,5 @@ namespace ICSharpCode.SharpDevelop
public static event EventHandler FileReplacing;
public static event EventHandler FileReplaced;
-
- public static event EventHandler JumpedToFilePosition;
}
}
diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs
index b871596520..a3ac1e8a18 100644
--- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs
+++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs
@@ -442,6 +442,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
#region IPositionable implementation
public void JumpTo(int line, int column)
{
+ textAreaControl.ActiveTextAreaControl.CenterViewOn(
+ line, (int)(0.3 * textAreaControl.ActiveTextAreaControl.TextArea.TextView.VisibleLineCount));
textAreaControl.ActiveTextAreaControl.JumpTo(line, column);
}