Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed http://community.sharpdevelop.net/forums/t/12009.aspx (when wor…

…d-wrapping is enabled and lines are very long, ScrollTo() does not find the correct position).
  • Loading branch information...
commit ff01c46e988456f78a8b77cc06a0d956ecba2a66 1 parent e866b3f
@dgrunwald dgrunwald authored
View
7 src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
@@ -547,15 +547,18 @@ public VisualLine GetOrConstructVisualLine(DocumentLine documentLine)
TextParagraphProperties paragraphProperties = CreateParagraphProperties(globalTextRunProperties);
while (heightTree.GetIsCollapsed(documentLine)) {
- documentLine = heightTree.GetLineByNumber(documentLine.LineNumber - 1);
+ documentLine = documentLine.PreviousLine;
}
l = BuildVisualLine(documentLine,
globalTextRunProperties, paragraphProperties,
elementGenerators.ToArray(), lineTransformers.ToArray(),
lastAvailableSize);
- l.VisualTop = heightTree.GetVisualPosition(documentLine);
allVisualLines.Add(l);
+ // update all visual top values (building the line might have changed visual top of other lines due to word wrapping)
+ foreach (var line in allVisualLines) {
+ line.VisualTop = heightTree.GetVisualPosition(line.FirstDocumentLine);
+ }
}
return l;
}
View
22 src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
@@ -7,11 +7,11 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Threading;
-
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting;
@@ -1065,7 +1065,25 @@ public void ScrollTo(int line, int column)
{
const double MinimumScrollPercentage = 0.3;
- if (scrollViewer != null) {
+ TextView textView = textArea.TextView;
+ TextDocument document = textView.Document;
+ if (scrollViewer != null && document != null) {
+ IScrollInfo scrollInfo = textView;
+ if (!scrollInfo.CanHorizontallyScroll) {
+ // Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
+ // to the correct position.
+ // This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
+ VisualLine vl = textView.GetOrConstructVisualLine(document.GetLineByNumber(line));
+ double remainingHeight = scrollViewer.ViewportHeight / 2;
+ while (remainingHeight > 0) {
+ DocumentLine prevLine = vl.FirstDocumentLine.PreviousLine;
+ if (prevLine == null)
+ break;
+ vl = textView.GetOrConstructVisualLine(prevLine);
+ remainingHeight -= vl.Height;
+ }
+ }
+
Point p = textArea.TextView.GetVisualPosition(new TextViewPosition(line, Math.Max(1, column)), VisualYPosition.LineMiddle);
double verticalPos = p.Y - scrollViewer.ViewportHeight / 2;
if (Math.Abs(verticalPos - scrollViewer.VerticalOffset) > MinimumScrollPercentage * scrollViewer.ViewportHeight) {
Please sign in to comment.
Something went wrong with that request. Please try again.