dnSpy.Text.Editor.MouseLocation.TryCreateTextOnly C# (CSharp) Method

TryCreateTextOnly() public static method

public static TryCreateTextOnly ( IWpfTextView wpfTextView, System.Windows.Input.MouseEventArgs e, bool fullLineHeight ) : MouseLocation
wpfTextView IWpfTextView
e System.Windows.Input.MouseEventArgs
fullLineHeight bool
return MouseLocation
		public static MouseLocation TryCreateTextOnly(IWpfTextView wpfTextView, MouseEventArgs e, bool fullLineHeight) {
			var point = GetTextPoint(wpfTextView, e);
			var line = wpfTextView.TextViewLines.GetTextViewLineContainingYCoordinate(point.Y);
			if (line == null)
				return null;
			if (fullLineHeight) {
				if (!(line.Top <= point.Y && point.Y < line.Bottom))
					return null;
				if (!(line.Left <= point.X && point.X < line.Right))
					return null;
			}
			else {
				if (!(line.TextTop <= point.Y && point.Y < line.TextBottom))
					return null;
				if (!(line.TextLeft <= point.X && point.X < line.TextRight))
					return null;
			}
			var position = line.GetBufferPositionFromXCoordinate(point.X, true);
			if (position == null)
				return null;

			return new MouseLocation(line, new VirtualSnapshotPoint(position.Value), point);
		}

Usage Example

示例#1
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();
                }
            }