From f5c4ab918b8f854ad1d9ad7d69eefee1cf3bc54c Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 1 Dec 2006 22:41:44 +0000 Subject: [PATCH] Fixed SD2-1156: JumpTo line position puts cursor at the bottom of the text editor git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2117 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Gui/TextAreaControl.cs | 29 +++++++++++++++++++ .../Project/Src/Services/File/FileService.cs | 9 ------ .../Gui/Editor/TextEditorDisplayBinding.cs | 2 ++ 3 files changed, 31 insertions(+), 9 deletions(-) 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); }