3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
import { Disposable , DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
6
- import { IActiveCodeEditor , ICodeEditor , IOverlayWidget , IOverlayWidgetPosition } from 'vs/editor/browser/editorBrowser' ;
6
+ import { IActiveCodeEditor , ICodeEditor , IOverlayWidget , IOverlayWidgetPosition , MouseTargetType } from 'vs/editor/browser/editorBrowser' ;
7
7
import * as dom from 'vs/base/browser/dom' ;
8
8
import { EditorLayoutInfo , EditorOption , RenderLineNumbersType } from 'vs/editor/common/config/editorOptions' ;
9
9
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder' ;
@@ -34,7 +34,6 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
34
34
private readonly layoutInfo : EditorLayoutInfo ;
35
35
private readonly rootDomNode : HTMLElement = document . createElement ( 'div' ) ;
36
36
private readonly disposableStore = this . _register ( new DisposableStore ( ) ) ;
37
- private readonly linkGestureStore = this . _register ( new DisposableStore ( ) ) ;
38
37
private lineHeight : number ;
39
38
private lineNumbers : number [ ] ;
40
39
private lastLineRelativePosition : number ;
@@ -45,7 +44,7 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
45
44
46
45
constructor (
47
46
private readonly _editor : ICodeEditor ,
48
- private readonly _languageFeatureService : ILanguageFeaturesService ,
47
+ @ ILanguageFeaturesService private readonly _languageFeatureService : ILanguageFeaturesService ,
49
48
@IInstantiationService private readonly _instaService : IInstantiationService
50
49
) {
51
50
super ( ) ;
@@ -72,28 +71,24 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
72
71
}
73
72
74
73
private updateLinkGesture ( ) : IDisposable {
75
- const gesture = this . linkGestureStore . add ( new ClickLinkGesture ( this . _editor ) ) ;
74
+ const linkGestureStore = new DisposableStore ( ) ;
75
+ const gesture = linkGestureStore . add ( new ClickLinkGesture ( this . _editor , true ) ) ;
76
76
const cancellationToken = new CancellationTokenSource ( ) ;
77
77
const sessionStore = new DisposableStore ( ) ;
78
78
sessionStore . add ( cancellationToken ) ;
79
- this . linkGestureStore . add ( sessionStore ) ;
80
- this . linkGestureStore . add ( gesture . onMouseMoveOrRelevantKeyDown ( ( [ mouseEvent , _keyboardEvent ] ) => {
81
- if ( ! this . _editor . hasModel ( ) ) {
82
- return ;
83
- }
84
- if ( ! mouseEvent . hasTriggerModifier ) {
85
- if ( this . lastChildDecorated ) {
86
- this . lastChildDecorated . style . textDecoration = 'none' ;
87
- this . lastChildDecorated = undefined ;
88
- }
79
+ linkGestureStore . add ( sessionStore ) ;
80
+ linkGestureStore . add ( gesture . onMouseMoveOrRelevantKeyDown ( ( [ mouseEvent , _keyboardEvent ] ) => {
81
+ if ( ! this . _editor . hasModel ( ) || ! mouseEvent . hasTriggerModifier ) {
82
+ sessionStore . clear ( ) ;
89
83
return ;
90
84
}
91
85
const targetMouseEvent = mouseEvent . target as any ;
92
86
if ( targetMouseEvent . detail === 'editor.contrib.stickyScrollWidget' && this . hoverOnLine !== - 1 && targetMouseEvent . element . innerText === targetMouseEvent . element . innerHTML ) {
93
87
const text = targetMouseEvent . element . innerText ;
94
88
const lineNumber = this . hoverOnLine ;
95
- const column = this . _editor . getModel ( ) ?. getLineContent ( lineNumber ) . indexOf ( text ) ;
96
- if ( ! column || column === - 1 ) {
89
+ // TODO: workaround to find the column index, perhaps need more solid solution
90
+ const column = this . _editor . getModel ( ) . getLineContent ( lineNumber ) . indexOf ( text ) ;
91
+ if ( column === - 1 ) {
97
92
return ;
98
93
}
99
94
const stickyPositionProjectedOnEditor = new Position ( lineNumber , column + 1 ) ;
@@ -141,10 +136,10 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
141
136
this . lastChildDecorated = undefined ;
142
137
}
143
138
} ) ) ;
144
- this . linkGestureStore . add ( gesture . onCancel ( ( ) => {
139
+ linkGestureStore . add ( gesture . onCancel ( ( ) => {
145
140
sessionStore . clear ( ) ;
146
141
} ) ) ;
147
- this . linkGestureStore . add ( gesture . onExecute ( async e => {
142
+ linkGestureStore . add ( gesture . onExecute ( async e => {
148
143
if ( this . hoverOnLine !== - 1 ) {
149
144
if ( e . hasTriggerModifier ) {
150
145
// Control click
@@ -156,7 +151,7 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
156
151
}
157
152
158
153
} ) ) ;
159
- return this . linkGestureStore ;
154
+ return linkGestureStore ;
160
155
}
161
156
162
157
public get codeLineCount ( ) : number {
@@ -310,7 +305,5 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
310
305
311
306
override dispose ( ) : void {
312
307
super . dispose ( ) ;
313
- this . linkGestureStore . dispose ( ) ;
314
- this . disposableStore . dispose ( ) ;
315
308
}
316
309
}
0 commit comments