in src/MiddleClickScroll/MiddleClickScroll.cs [159:222]
private void OnTimerElapsed(object sender, EventArgs e)
{
if ((!_view.IsClosed) && (_view.VisualElement.IsVisible) && _location.HasValue)
{
DateTime now = DateTime.Now;
Point currentPosition = _view.VisualElement.PointToScreen(Mouse.GetPosition(_view.VisualElement));
var delta = currentPosition - _location.Value;
double absDeltaX = Math.Abs(delta.X);
double absDeltaY = Math.Abs(delta.Y);
double maxDelta = Math.Max(absDeltaX, absDeltaY);
if (maxDelta > minMove)
{
_dismissOnMouseUp = true;
double deltaT = (now - _lastMoveTime).TotalMilliseconds;
double pixels = (maxDelta - minMove) * deltaT / moveDivisor;
if (absDeltaX > absDeltaY)
{
if (delta.X > 0.0)
{
_view.ViewportLeft += pixels;
_view.VisualElement.Cursor = Cursors.ScrollE;
}
else
{
_view.ViewportLeft -= pixels;
_view.VisualElement.Cursor = Cursors.ScrollW;
}
}
else
{
ITextViewLine top = _view.TextViewLines[0];
double newOffset = top.Top - _view.ViewportTop;
if (delta.Y > 0.0)
{
newOffset = (newOffset - pixels);
_view.VisualElement.Cursor = Cursors.ScrollS;
}
else
{
newOffset = (newOffset + pixels);
_view.VisualElement.Cursor = Cursors.ScrollN;
}
_view.DisplayTextLineContainingBufferPosition(top.Start, newOffset, ViewRelativePosition.Top);
}
}
else
{
_view.VisualElement.Cursor = Cursors.ScrollAll;
}
_lastMoveTime = now;
}
else
{
this.StopScrolling();
}
}