Skip to content

Commit

Permalink
Updated mouse processor to work on mouse-up, and work around some of …
Browse files Browse the repository at this point in the history
…the issues that go along with that. It should now work better with drag/drop and the word selection logic. Bumped to v2.2.
  • Loading branch information
Noah Richards committed Jun 22, 2010
1 parent e4fa098 commit 5939a29
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Classifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void SendEvent(SnapshotSpan span)

#region UnderlineClassification public members

public SnapshotSpan? CurrentUnderlineSpan { get { return _underlineSpan; } }

public void SetUnderlineSpan(SnapshotSpan? span)
{
var oldSpan = _underlineSpan;
Expand Down
61 changes: 52 additions & 9 deletions GoToDefMouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,49 @@ internal sealed class GoToDefMouseHandler : MouseProcessorBase

#region Mouse processor overrides

// Remember the location of the mouse on left button down, so we only handle left button up
// if the mouse has stayed in a single location.
Point? _mouseDownAnchorPoint;

public override void PostprocessMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (_state.Enabled)
{
_state.Enabled = false;
this.SetHighlightSpan(null);
this.DispatchGoToDef();
}
_mouseDownAnchorPoint = RelativeToView(e.GetPosition(_view.VisualElement));
}

public override void PreprocessMouseMove(MouseEventArgs e)
{
if (_state.Enabled)
if (!_mouseDownAnchorPoint.HasValue && _state.Enabled)
{
TryHighlightItemUnderMouse(RelativeToView(e.GetPosition(_view.VisualElement)));
}
}

public override void PreprocessMouseLeave(MouseEventArgs e)
{
_mouseDownAnchorPoint = null;
}

public override void PreprocessMouseUp(MouseButtonEventArgs e)
{
if (_mouseDownAnchorPoint.HasValue && _state.Enabled)
{
var currentMousePosition = RelativeToView(e.GetPosition(_view.VisualElement));

// If the mouse up was less than a drag away from the mouse down, consider this a click
if (Math.Abs(_mouseDownAnchorPoint.Value.X - currentMousePosition.X) < SystemParameters.MinimumHorizontalDragDistance &&
Math.Abs(_mouseDownAnchorPoint.Value.Y - currentMousePosition.Y) < SystemParameters.MinimumVerticalDragDistance)
{
_state.Enabled = false;

this.SetHighlightSpan(null);
_view.Selection.Clear();
this.DispatchGoToDef();

e.Handled = true;
}

// Don't mark the event as handled, so other mouse processors have a chance to do their work
// (such as clicking+dragging to select text)
_mouseDownAnchorPoint = null;
}
}

#endregion
Expand All @@ -225,6 +249,14 @@ bool TryHighlightItemUnderMouse(Point position)
if (!bufferPosition.HasValue)
return false;

// Quick check - if the mouse is still inside the current underline span, we're already set
var currentSpan = CurrentUnderlineSpan;
if (currentSpan.HasValue && currentSpan.Value.Contains(bufferPosition.Value))
{
updated = true;
return true;
}

var extent = _navigator.GetExtentOfWord(bufferPosition.Value);
if (!extent.IsSignificant)
return false;
Expand Down Expand Up @@ -261,6 +293,17 @@ bool TryHighlightItemUnderMouse(Point position)
}
}

SnapshotSpan? CurrentUnderlineSpan
{
get
{
var classifier = UnderlineClassifierProvider.GetClassifierForView(_view);
if (classifier != null && classifier.CurrentUnderlineSpan.HasValue)
return classifier.CurrentUnderlineSpan.Value.TranslateTo(_view.TextSnapshot, SpanTrackingMode.EdgeExclusive);
else
return null;
}
}

bool SetHighlightSpan(SnapshotSpan? span)
{
Expand Down
2 changes: 1 addition & 1 deletion source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Identifier Id="GoToDef">
<Name>Go To Definition</Name>
<Author>Noah Richards</Author>
<Version>2.1</Version>
<Version>2.2</Version>
<Description xml:space="preserve">Make ctrl+click perform a "Go To Definition" on the identifier under the cursor.
Also, when the ctrl key is held down, highlight identifiers that look like they have
definitions to navigate to.</Description>
Expand Down

0 comments on commit 5939a29

Please sign in to comment.