ScrollDirection?GetScrollDirection(MouseLocation mouseLoc, out TimeSpan interval)
 {
     // Give prio to scrolling up/down (more common than scrolling left/right)
     if (mouseLoc.Point.Y < wpfTextView.ViewportTop)
     {
         interval = GetVerticalInterval(mouseLoc.Point.Y - wpfTextView.ViewportTop);
         return(ScrollDirection.Up);
     }
     if (mouseLoc.Point.Y >= wpfTextView.ViewportBottom)
     {
         interval = GetVerticalInterval(mouseLoc.Point.Y - wpfTextView.ViewportBottom);
         return(ScrollDirection.Down);
     }
     if (mouseLoc.Point.X < wpfTextView.ViewportLeft)
     {
         interval = GetHorizontalInterval(mouseLoc.Point.X - wpfTextView.ViewportLeft);
         return(ScrollDirection.Left);
     }
     if (mouseLoc.Point.X >= wpfTextView.ViewportRight)
     {
         interval = GetHorizontalInterval(mouseLoc.Point.X - wpfTextView.ViewportRight);
         return(ScrollDirection.Right);
     }
     interval = TimeSpan.Zero;
     return(null);
 }
示例#2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (mouseCaptured)
            {
                var mouseLoc = MouseLocation.Create(wpfTextViewHost.TextView, e, insertionPosition: false);
                var line     = mouseLoc.TextViewLine;
                editorOperations.SelectLine(line, true);
                // Needed or the scrolling will stop
                if (mouseLoc.Point.Y <= wpfTextViewHost.TextView.ViewportTop)
                {
                    editorOperations.ScrollUpAndMoveCaretIfNecessary();
                }
                else if (mouseLoc.Point.Y >= wpfTextViewHost.TextView.ViewportBottom)
                {
                    var lastVisLine = wpfTextViewHost.TextView.TextViewLines.LastVisibleLine;
                    if (!lastVisLine.IsLastDocumentLine() || lastVisLine.VisibilityState != VisibilityState.FullyVisible)
                    {
                        editorOperations.ScrollDownAndMoveCaretIfNecessary();
                    }
                }
                e.Handled = true;
                return;
            }

            base.OnMouseMove(e);
        }
		void SelectToMousePosition(MouseLocation mouseLoc, bool extendSelection, bool allowVirtualSpace) {
			UpdateSelectionMode();
			var snapshotLine = mouseLoc.TextViewLine.Start.GetContainingLine();
			editorOperations.MoveCaret(mouseLoc.TextViewLine, mouseLoc.Point.X, extendSelection);
			if (wpfTextView.Selection.Mode == TextSelectionMode.Box)
				allowVirtualSpace = true;
			// The caret can move to an auto-indented location if the line is empty. Move to
			// the first character if the user clicked somewhere before the auto-indented location.
			if (!allowVirtualSpace && snapshotLine.Length == 0 && mouseLoc.Point.X < wpfTextView.Caret.Left)
				editorOperations.MoveCaret(mouseLoc.TextViewLine, 0, extendSelection);
		}
示例#4
0
            void WpfTextView_MouseMove(object sender, MouseEventArgs e)
            {
                if (owner.IsClosed || owner.IsMouseOverOverlayLayerElement(e))
                {
                    ClearMouseHoverPositionAndStopTimer();
                    return;
                }
                if (e.LeftButton != MouseButtonState.Released || e.RightButton != MouseButtonState.Released || e.MiddleButton != MouseButtonState.Released)
                {
                    return;
                }

                var loc = MouseLocation.TryCreateTextOnly(owner, e);
                int?newPosition;

                if (loc == null)
                {
                    newPosition = null;
                }
                else if (loc.Position.IsInVirtualSpace)
                {
                    newPosition = null;
                }
                else if (!(loc.TextViewLine.TextTop <= loc.Point.Y && loc.Point.Y < loc.TextViewLine.TextBottom))
                {
                    newPosition = null;
                }
                else if (!(loc.TextViewLine.TextLeft <= loc.Point.X && loc.Point.X < loc.TextViewLine.TextRight))
                {
                    newPosition = null;
                }
                else
                {
                    int pos = loc.Position.Position.Position;
                    if (loc.Affinity == PositionAffinity.Predecessor && pos != 0)
                    {
                        pos--;
                    }
                    newPosition = pos;
                }

                if (newPosition != position)
                {
                    position = newPosition;
                    StopTimer();
                    foreach (var h in handlers)
                    {
                        h.Raised = false;
                    }
                    UpdateTimer();
                }
            }
示例#5
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (CaptureMouse())
            {
                var line = MouseLocation.Create(wpfTextViewHost.TextView, e, insertionPosition: false).TextViewLine;
                editorOperations.SelectLine(line, (Keyboard.Modifiers & ModifierKeys.Shift) != 0);
                mouseCaptured = true;
                e.Handled     = true;
                return;
            }

            base.OnMouseLeftButtonDown(e);
        }
示例#6
0
        IMappingTagSpan <IUrlTag> GetUriSpan(MouseEventArgs e)
        {
            if (!IsControlDown)
            {
                return(null);
            }
            var loc = MouseLocation.Create(wpfTextView, e, insertionPosition: false);

            if (loc.Position.VirtualSpaces > 0)
            {
                return(null);
            }
            return(UriHelper.GetUri(viewTagAggregatorFactoryService, wpfTextView, loc.Position.Position));
        }
示例#7
0
        SnapshotSpan?GetUriSpan(MouseEventArgs e)
        {
            if (!IsControlDown)
            {
                return(null);
            }
            var loc = MouseLocation.Create(wpfTextView, e);

            if (loc.Position.VirtualSpaces > 0)
            {
                return(null);
            }
            return(UriHelper.GetUri(viewTagAggregatorFactoryService, wpfTextView, loc.Position.Position));
        }
        void SelectToMousePosition(MouseLocation mouseLoc, bool extendSelection, bool allowVirtualSpace)
        {
            UpdateSelectionMode();
            var snapshotLine = mouseLoc.TextViewLine.Start.GetContainingLine();

            editorOperations.MoveCaret(mouseLoc.TextViewLine, mouseLoc.Point.X, extendSelection);
            if (wpfTextView.Selection.Mode == TextSelectionMode.Box)
            {
                allowVirtualSpace = true;
            }
            // The caret can move to an auto-indented location if the line is empty. Move to
            // the first character if the user clicked somewhere before the auto-indented location.
            if (!allowVirtualSpace && snapshotLine.Length == 0 && mouseLoc.Point.X < wpfTextView.Caret.Left)
            {
                editorOperations.MoveCaret(mouseLoc.TextViewLine, 0, extendSelection);
            }
        }
示例#9
0
        static TextEditorPosition GetTextEditorPositionFromMouse(IWpfTextView textView)
        {
            if (!textView.VisualElement.IsVisible)
            {
                return(null);
            }
            var loc = MouseLocation.Create(textView, new MouseEventArgs(Mouse.PrimaryDevice, 0), insertionPosition: true);

            if (loc.Point.Y < textView.ViewportTop || loc.Point.Y >= textView.ViewportBottom)
            {
                return(null);
            }
            if (loc.Point.X < textView.ViewportLeft || loc.Point.X >= textView.ViewportRight)
            {
                return(null);
            }
            return(new TextEditorPosition(loc.Position));
        }
 MouseLocation GetLocation(MouseEventArgs e) => MouseLocation.Create(wpfTextView, e, insertionPosition: true);
		ScrollDirection? GetScrollDirection(MouseLocation mouseLoc, out TimeSpan interval) {
			// Give prio to scrolling up/down (more common than scrolling left/right)
			if (mouseLoc.Point.Y < wpfTextView.ViewportTop) {
				interval = GetVerticalInterval(mouseLoc.Point.Y - wpfTextView.ViewportTop);
				return ScrollDirection.Up;
			}
			if (mouseLoc.Point.Y >= wpfTextView.ViewportBottom) {
				interval = GetVerticalInterval(mouseLoc.Point.Y - wpfTextView.ViewportBottom);
				return ScrollDirection.Down;
			}
			if (mouseLoc.Point.X < wpfTextView.ViewportLeft) {
				interval = GetHorizontalInterval(mouseLoc.Point.X - wpfTextView.ViewportLeft);
				return ScrollDirection.Left;
			}
			if (mouseLoc.Point.X >= wpfTextView.ViewportRight) {
				interval = GetHorizontalInterval(mouseLoc.Point.X - wpfTextView.ViewportRight);
				return ScrollDirection.Right;
			}
			interval = TimeSpan.Zero;
			return null;
		}
示例#12
0
 MouseLocation GetLocation(MouseEventArgs e) => MouseLocation.Create(wpfTextView, e);