@@ -180,25 +180,49 @@ public GoToDefMouseHandler(IWpfTextView view, IOleCommandTarget commandTarget, I
180
180
181
181
#region Mouse processor overrides
182
182
183
+ // Remember the location of the mouse on left button down, so we only handle left button up
184
+ // if the mouse has stayed in a single location.
185
+ Point ? _mouseDownAnchorPoint ;
186
+
183
187
public override void PostprocessMouseLeftButtonDown ( MouseButtonEventArgs e )
184
188
{
185
- if ( _state . Enabled )
186
- {
187
- _state . Enabled = false ;
188
- this . SetHighlightSpan ( null ) ;
189
- this . DispatchGoToDef ( ) ;
190
- }
189
+ _mouseDownAnchorPoint = RelativeToView ( e . GetPosition ( _view . VisualElement ) ) ;
191
190
}
192
191
193
192
public override void PreprocessMouseMove ( MouseEventArgs e )
194
193
{
195
- if ( _state . Enabled )
194
+ if ( ! _mouseDownAnchorPoint . HasValue && _state . Enabled )
196
195
{
197
196
TryHighlightItemUnderMouse ( RelativeToView ( e . GetPosition ( _view . VisualElement ) ) ) ;
198
197
}
198
+ }
199
+
200
+ public override void PreprocessMouseLeave ( MouseEventArgs e )
201
+ {
202
+ _mouseDownAnchorPoint = null ;
203
+ }
204
+
205
+ public override void PreprocessMouseUp ( MouseButtonEventArgs e )
206
+ {
207
+ if ( _mouseDownAnchorPoint . HasValue && _state . Enabled )
208
+ {
209
+ var currentMousePosition = RelativeToView ( e . GetPosition ( _view . VisualElement ) ) ;
210
+
211
+ // If the mouse up was less than a drag away from the mouse down, consider this a click
212
+ if ( Math . Abs ( _mouseDownAnchorPoint . Value . X - currentMousePosition . X ) < SystemParameters . MinimumHorizontalDragDistance &&
213
+ Math . Abs ( _mouseDownAnchorPoint . Value . Y - currentMousePosition . Y ) < SystemParameters . MinimumVerticalDragDistance )
214
+ {
215
+ _state . Enabled = false ;
216
+
217
+ this . SetHighlightSpan ( null ) ;
218
+ _view . Selection . Clear ( ) ;
219
+ this . DispatchGoToDef ( ) ;
220
+
221
+ e . Handled = true ;
222
+ }
199
223
200
- // Don't mark the event as handled, so other mouse processors have a chance to do their work
201
- // (such as clicking+dragging to select text)
224
+ _mouseDownAnchorPoint = null ;
225
+ }
202
226
}
203
227
204
228
#endregion
@@ -225,6 +249,14 @@ bool TryHighlightItemUnderMouse(Point position)
225
249
if ( ! bufferPosition . HasValue )
226
250
return false ;
227
251
252
+ // Quick check - if the mouse is still inside the current underline span, we're already set
253
+ var currentSpan = CurrentUnderlineSpan ;
254
+ if ( currentSpan . HasValue && currentSpan . Value . Contains ( bufferPosition . Value ) )
255
+ {
256
+ updated = true ;
257
+ return true ;
258
+ }
259
+
228
260
var extent = _navigator . GetExtentOfWord ( bufferPosition . Value ) ;
229
261
if ( ! extent . IsSignificant )
230
262
return false ;
@@ -261,6 +293,17 @@ bool TryHighlightItemUnderMouse(Point position)
261
293
}
262
294
}
263
295
296
+ SnapshotSpan ? CurrentUnderlineSpan
297
+ {
298
+ get
299
+ {
300
+ var classifier = UnderlineClassifierProvider . GetClassifierForView ( _view ) ;
301
+ if ( classifier != null && classifier . CurrentUnderlineSpan . HasValue )
302
+ return classifier . CurrentUnderlineSpan . Value . TranslateTo ( _view . TextSnapshot , SpanTrackingMode . EdgeExclusive ) ;
303
+ else
304
+ return null ;
305
+ }
306
+ }
264
307
265
308
bool SetHighlightSpan ( SnapshotSpan ? span )
266
309
{
0 commit comments