33 * @license MIT
44 */
55
6- import { ILinkifier2 , ILinkProvider , IBufferCellPosition , ILink , ILinkifierEvent } from './Types' ;
6+ import { ILinkifier2 , ILinkProvider , IBufferCellPosition , ILink , ILinkifierEvent , ILinkDecorations } from './Types' ;
77import { IDisposable } from 'common/Types' ;
88import { IMouseService , IRenderService } from './services/Services' ;
99import { IBufferService } from 'common/services/Services' ;
1010import { EventEmitter , IEvent } from 'common/EventEmitter' ;
1111
1212interface ILinkState {
13- hideDecorations : boolean ;
13+ decorations : ILinkDecorations ;
1414 isHovered : boolean ;
1515}
1616
@@ -20,7 +20,7 @@ export class Linkifier2 implements ILinkifier2 {
2020 private _renderService : IRenderService | undefined ;
2121 private _linkProviders : ILinkProvider [ ] = [ ] ;
2222 private _currentLink : ILink | undefined ;
23- private _currentLinkState : ILinkState | undefined ;
23+ protected _currentLinkState : ILinkState | undefined ;
2424 private _lastMouseEvent : MouseEvent | undefined ;
2525 private _linkCacheDisposables : IDisposable [ ] = [ ] ;
2626 private _lastBufferCell : IBufferCellPosition | undefined ;
@@ -199,21 +199,35 @@ export class Linkifier2 implements ILinkifier2 {
199199 if ( this . _linkAtPosition ( link , position ) ) {
200200 this . _currentLink = link ;
201201 this . _currentLinkState = {
202- hideDecorations : link . hideDecorations || false ,
202+ decorations : {
203+ underline : link . decorations === undefined ? true : link . decorations . underline ,
204+ pointerCursor : link . decorations === undefined ? true : link . decorations . pointerCursor
205+ } ,
203206 isHovered : true
204207 } ;
205208 this . _linkHover ( this . _element , link , this . _lastMouseEvent ) ;
206209
207- // Add listener for tracking hideDecorations changes
208- Object . defineProperties ( link , {
209- hideDecorations : {
210- get : ( ) => this . _currentLinkState ?. hideDecorations ,
210+ // Add listener for tracking decorations changes
211+ link . decorations = { } as ILinkDecorations ;
212+ Object . defineProperties ( link . decorations , {
213+ pointerCursor : {
214+ get : ( ) => this . _currentLinkState ?. decorations . pointerCursor ,
211215 set : v => {
212- if ( this . _currentLinkState && this . _currentLinkState . hideDecorations !== v ) {
213- this . _currentLinkState . hideDecorations = v ;
214- if ( this . _currentLinkState ?. isHovered ) {
215- this . _fireUnderlineEvent ( link , ! v ) ;
216- this . _element ?. classList . toggle ( 'xterm-cursor-pointer' , ! v ) ;
216+ if ( this . _currentLinkState && this . _currentLinkState ?. decorations . pointerCursor !== v ) {
217+ this . _currentLinkState . decorations . pointerCursor = v ;
218+ if ( this . _currentLinkState . isHovered ) {
219+ this . _element ?. classList . toggle ( 'xterm-cursor-pointer' , v ) ;
220+ }
221+ }
222+ }
223+ } ,
224+ underline : {
225+ get : ( ) => this . _currentLinkState ?. decorations . underline ,
226+ set : v => {
227+ if ( this . _currentLinkState && this . _currentLinkState ?. decorations . underline !== v ) {
228+ this . _currentLinkState . decorations . underline = v ;
229+ if ( this . _currentLinkState . isHovered ) {
230+ this . _fireUnderlineEvent ( link , v ) ;
217231 }
218232 }
219233 }
@@ -230,12 +244,14 @@ export class Linkifier2 implements ILinkifier2 {
230244 }
231245
232246 protected _linkHover ( element : HTMLElement , link : ILink , event : MouseEvent ) : void {
233- if ( ! link . hideDecorations ) {
234- this . _fireUnderlineEvent ( link , true ) ;
235- element . classList . add ( 'xterm-cursor-pointer' ) ;
236- }
237247 if ( this . _currentLinkState ) {
238248 this . _currentLinkState . isHovered = true ;
249+ if ( this . _currentLinkState . decorations . underline ) {
250+ this . _fireUnderlineEvent ( link , true ) ;
251+ }
252+ if ( this . _currentLinkState . decorations . pointerCursor ) {
253+ element . classList . add ( 'xterm-cursor-pointer' ) ;
254+ }
239255 }
240256
241257 if ( link . hover ) {
@@ -252,12 +268,14 @@ export class Linkifier2 implements ILinkifier2 {
252268 }
253269
254270 protected _linkLeave ( element : HTMLElement , link : ILink , event : MouseEvent ) : void {
255- if ( ! link . hideDecorations ) {
256- this . _fireUnderlineEvent ( link , false ) ;
257- element . classList . remove ( 'xterm-cursor-pointer' ) ;
258- }
259271 if ( this . _currentLinkState ) {
260272 this . _currentLinkState . isHovered = false ;
273+ if ( this . _currentLinkState . decorations . underline ) {
274+ this . _fireUnderlineEvent ( link , false ) ;
275+ }
276+ if ( this . _currentLinkState . decorations . pointerCursor ) {
277+ element . classList . remove ( 'xterm-cursor-pointer' ) ;
278+ }
261279 }
262280
263281 if ( link . leave ) {
0 commit comments