@@ -24,28 +24,43 @@ export default class TextHover {
24
24
constructor ( editor , highlighter ) {
25
25
this . editor = editor ;
26
26
this . highlighter = highlighter ;
27
- this . matches = null ;
27
+ this . _matches = this . _x = null ;
28
28
29
29
let o = editor . display . lineDiv ;
30
30
o . addEventListener ( "mousemove" , ( evt ) => this . _handleMouseMove ( evt ) ) ;
31
31
o . addEventListener ( "mouseout" , ( evt ) => this . _handleMouseOut ( evt ) ) ;
32
32
}
33
33
34
+ set matches ( val ) {
35
+ this . _matches = val ;
36
+ this . _update ( ) ;
37
+ }
34
38
35
39
// private methods:
36
40
_handleMouseMove ( evt ) {
37
- let index , cm = this . editor , match , matches = this . matches ;
41
+ this . _x = evt . clientX ;
42
+ this . _y = evt . clientY + window . pageYOffset ;
43
+ this . _update ( ) ;
44
+ }
45
+
46
+ _handleMouseOut ( evt ) {
47
+ this . _x = null ;
48
+ this . _update ( ) ;
49
+ }
50
+
51
+ _update ( ) {
52
+ if ( this . _x === null ) {
53
+ this . highlighter . hoverMatch = null ;
54
+ app . tooltip . hover . hide ( "TextHover" ) ;
55
+ return ;
56
+ }
57
+ let index , cm = this . editor , match , matches = this . _matches , x = this . _x , y = this . _y ;
38
58
39
- if ( matches && matches . length && ( index = CMUtils . getCharIndexAt ( cm , evt . clientX , evt . clientY + window . pageYOffset ) ) != null ) {
59
+ if ( matches && matches . length && ( index = CMUtils . getCharIndexAt ( cm , x , y ) ) != null ) {
40
60
match = this . highlighter . hoverMatch = app . text . getMatchAt ( index ) ;
41
61
}
42
62
let rect = ( index != null ) && CMUtils . getCharRect ( cm , index ) ;
43
- if ( rect ) { rect . right = rect . left = evt . clientX ; }
44
- app . tooltip . hover . show ( "TextHover" , app . reference . tipForMatch ( match , cm . getValue ( ) ) , evt . clientX , rect . bottom , true , 0 ) ;
45
- }
46
-
47
- _handleMouseOut ( evt ) {
48
- this . highlighter . hoverMatch = null ;
49
- app . tooltip . hover . hide ( "TextHover" ) ;
63
+ if ( rect ) { rect . right = rect . left = x ; }
64
+ app . tooltip . hover . show ( "TextHover" , app . reference . tipForMatch ( match , cm . getValue ( ) ) , x , rect . bottom , true , 0 ) ;
50
65
}
51
66
}
0 commit comments