Browse Source

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
shortcuts
Daniel Grunwald 19 years ago
parent
commit
f5c4ab918b
  1. 29
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs
  2. 9
      src/Main/Base/Project/Src/Services/File/FileService.cs
  3. 2
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs

29
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaControl.cs

@ -351,6 +351,9 @@ namespace ICSharpCode.TextEditor
int scrollMarginHeight = 3; int scrollMarginHeight = 3;
/// <summary>
/// Ensure that <paramref name="line"/> is visible.
/// </summary>
public void ScrollTo(int line) public void ScrollTo(int line)
{ {
line = Math.Max(0, Math.Min(Document.TotalNumberOfLines - 1, line)); line = Math.Max(0, Math.Min(Document.TotalNumberOfLines - 1, line));
@ -377,6 +380,32 @@ namespace ICSharpCode.TextEditor
} }
} }
/// <summary>
/// Scroll so that the specified line is centered.
/// </summary>
/// <param name="line">Line to center view on</param>
/// <param name="treshold">If this action would cause scrolling by less than or equal to
/// <paramref name="treshold"/> lines in any direction, don't scroll.
/// Use -1 to always center the view.</param>
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) public void JumpTo(int line)
{ {
line = Math.Min(line, Document.TotalNumberOfLines - 1); line = Math.Min(line, Document.TotalNumberOfLines - 1);

9
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<FileRenamingEventArgs> FileRenaming; public static event EventHandler<FileRenamingEventArgs> FileRenaming;
public static event EventHandler<FileRenameEventArgs> FileRenamed; public static event EventHandler<FileRenameEventArgs> FileRenamed;
@ -298,7 +291,5 @@ namespace ICSharpCode.SharpDevelop
public static event EventHandler<FileCancelEventArgs> FileReplacing; public static event EventHandler<FileCancelEventArgs> FileReplacing;
public static event EventHandler<FileEventArgs> FileReplaced; public static event EventHandler<FileEventArgs> FileReplaced;
public static event EventHandler<FileEventArgs> JumpedToFilePosition;
} }
} }

2
src/Main/Base/Project/Src/TextEditor/Gui/Editor/TextEditorDisplayBinding.cs

@ -442,6 +442,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
#region IPositionable implementation #region IPositionable implementation
public void JumpTo(int line, int column) public void JumpTo(int line, int column)
{ {
textAreaControl.ActiveTextAreaControl.CenterViewOn(
line, (int)(0.3 * textAreaControl.ActiveTextAreaControl.TextArea.TextView.VisibleLineCount));
textAreaControl.ActiveTextAreaControl.JumpTo(line, column); textAreaControl.ActiveTextAreaControl.JumpTo(line, column);
} }

Loading…
Cancel
Save