@@ -30,25 +30,28 @@ class TerminalHighlightContribution extends Disposable implements ITerminalContr
30
30
31
31
xtermOpen ( xterm : IXtermTerminal & { raw : RawXtermTerminal } ) : void {
32
32
const screenElement = xterm . raw . element ! . querySelector ( '.xterm-screen' ) ! ;
33
- this . _register ( addDisposableListener ( screenElement , 'mousemove' , ( e : MouseEvent ) => {
34
- if ( ( e . target as any ) . tagName !== 'CANVAS' ) {
35
- return ;
36
- }
37
- const rect = xterm . raw . element ?. getBoundingClientRect ( ) ;
38
- if ( ! rect ) {
39
- return ;
40
- }
41
- const mouseCursorY = Math . floor ( e . offsetY / ( rect . height / xterm . raw . rows ) ) ;
42
- const command = this . _instance . capabilities . get ( TerminalCapability . CommandDetection ) ?. getCommandForLine ( xterm . raw . buffer . active . viewportY + mouseCursorY ) ;
43
- if ( command && 'getOutput' in command ) {
44
- xterm . markTracker . showCommandGuide ( command ) ;
45
- } else {
46
- xterm . markTracker . showCommandGuide ( undefined ) ;
47
- }
48
- } ) ) ;
49
- this . _register ( addDisposableListener ( screenElement , 'mouseout' , ( ) => xterm . markTracker . showCommandGuide ( undefined ) ) ) ;
33
+ this . _register ( addDisposableListener ( screenElement , 'mousemove' , ( e : MouseEvent ) => this . _tryShowHighlight ( screenElement , xterm , e ) ) ) ;
34
+
35
+ const viewportElement = xterm . raw . element ! . querySelector ( '.xterm-viewport' ) ! ;
36
+ this . _register ( addDisposableListener ( viewportElement , 'mousemove' , ( e : MouseEvent ) => this . _tryShowHighlight ( screenElement , xterm , e ) ) ) ;
37
+
38
+ this . _register ( addDisposableListener ( xterm . raw . element ! , 'mouseout' , ( ) => xterm . markTracker . showCommandGuide ( undefined ) ) ) ;
50
39
this . _register ( xterm . raw . onData ( ( ) => xterm . markTracker . showCommandGuide ( undefined ) ) ) ;
51
40
}
41
+
42
+ private _tryShowHighlight ( element : Element , xterm : IXtermTerminal & { raw : RawXtermTerminal } , e : MouseEvent ) {
43
+ const rect = element . getBoundingClientRect ( ) ;
44
+ if ( ! rect ) {
45
+ return ;
46
+ }
47
+ const mouseCursorY = Math . floor ( e . offsetY / ( rect . height / xterm . raw . rows ) ) ;
48
+ const command = this . _instance . capabilities . get ( TerminalCapability . CommandDetection ) ?. getCommandForLine ( xterm . raw . buffer . active . viewportY + mouseCursorY ) ;
49
+ if ( command && 'getOutput' in command ) {
50
+ xterm . markTracker . showCommandGuide ( command ) ;
51
+ } else {
52
+ xterm . markTracker . showCommandGuide ( undefined ) ;
53
+ }
54
+ }
52
55
}
53
56
54
57
registerTerminalContribution ( TerminalHighlightContribution . ID , TerminalHighlightContribution , false ) ;
0 commit comments