@@ -239,7 +239,8 @@ class GotoDefinitionWithMouseEditorContribution implements EditorCommon.IEditorC
239239 private decorations :string [ ] ;
240240 private currentWordUnderMouse :EditorCommon . IWordAtPosition ;
241241 private throttler :Async . Throttler ;
242- private lastMouseEvent :EditorBrowser . IMouseEvent ;
242+ private lastMouseMoveEvent :EditorBrowser . IMouseEvent ;
243+ private hasTriggerKeyOnMouseDown :boolean ;
243244
244245 constructor ( editor : EditorBrowser . ICodeEditor , @IRequestService requestService : IRequestService , @IMessageService messageService : IMessageService , @IEditorService editorService : IEditorService ) {
245246 this . editorService = editorService ;
@@ -252,6 +253,7 @@ class GotoDefinitionWithMouseEditorContribution implements EditorCommon.IEditorC
252253 this . editor = editor ;
253254 this . throttler = new Async . Throttler ( ) ;
254255
256+ this . toUnhook . push ( this . editor . addListener ( EditorCommon . EventType . MouseDown , ( e :EditorBrowser . IMouseEvent ) => this . onEditorMouseDown ( e ) ) ) ;
255257 this . toUnhook . push ( this . editor . addListener ( EditorCommon . EventType . MouseUp , ( e :EditorBrowser . IMouseEvent ) => this . onEditorMouseUp ( e ) ) ) ;
256258 this . toUnhook . push ( this . editor . addListener ( EditorCommon . EventType . MouseMove , ( e :EditorBrowser . IMouseEvent ) => this . onEditorMouseMove ( e ) ) ) ;
257259 this . toUnhook . push ( this . editor . addListener ( EditorCommon . EventType . KeyDown , ( e :Keyboard . StandardKeyboardEvent ) => this . onEditorKeyDown ( e ) ) ) ;
@@ -263,7 +265,7 @@ class GotoDefinitionWithMouseEditorContribution implements EditorCommon.IEditorC
263265 }
264266
265267 private onEditorMouseMove ( mouseEvent : EditorBrowser . IMouseEvent , withKey ?:Keyboard . StandardKeyboardEvent ) :void {
266- this . lastMouseEvent = mouseEvent ;
268+ this . lastMouseMoveEvent = mouseEvent ;
267269
268270 this . startFindDefinition ( mouseEvent , withKey ) ;
269271 }
@@ -410,20 +412,28 @@ class GotoDefinitionWithMouseEditorContribution implements EditorCommon.IEditorC
410412 }
411413
412414 private onEditorKeyDown ( e :Keyboard . StandardKeyboardEvent ) :void {
413- if ( e . keyCode === GotoDefinitionWithMouseEditorContribution . TRIGGER_KEY_VALUE && this . lastMouseEvent ) {
414- this . startFindDefinition ( this . lastMouseEvent , e ) ;
415+ if ( e . keyCode === GotoDefinitionWithMouseEditorContribution . TRIGGER_KEY_VALUE && this . lastMouseMoveEvent ) {
416+ this . startFindDefinition ( this . lastMouseMoveEvent , e ) ;
415417 } else if ( e [ GotoDefinitionWithMouseEditorContribution . TRIGGER_MODIFIER ] ) {
416418 this . removeDecorations ( ) ; // remove decorations if user holds another key with ctrl/cmd to prevent accident goto declaration
417419 }
418420 }
419421
420422 private resetHandler ( ) :void {
421- this . lastMouseEvent = null ;
423+ this . lastMouseMoveEvent = null ;
422424 this . removeDecorations ( ) ;
423425 }
424426
427+ private onEditorMouseDown ( mouseEvent : EditorBrowser . IMouseEvent ) :void {
428+ // We need to record if we had the trigger key on mouse down because someone might select something in the editor
429+ // holding the mouse down and then while mouse is down start to press Ctrl/Cmd to start a copy operation and then
430+ // release the mouse button without wanting to do the navigation.
431+ // With this flag we prevent goto definition if the mouse was down before the trigger key was pressed.
432+ this . hasTriggerKeyOnMouseDown = ! ! mouseEvent . event [ GotoDefinitionWithMouseEditorContribution . TRIGGER_MODIFIER ] ;
433+ }
434+
425435 private onEditorMouseUp ( mouseEvent : EditorBrowser . IMouseEvent ) :void {
426- if ( this . isEnabled ( mouseEvent ) ) {
436+ if ( this . isEnabled ( mouseEvent ) && this . hasTriggerKeyOnMouseDown ) {
427437 this . gotoDefinition ( mouseEvent . target , mouseEvent . event . altKey ) . done ( ( ) => {
428438 this . removeDecorations ( ) ;
429439 } , ( error :Error ) => {
0 commit comments