@@ -34,6 +34,7 @@ SOFTWARE.
34
34
p . highlighter = null ;
35
35
p . token = null ;
36
36
p . offset = 0 ;
37
+ p . isMouseDown = false ;
37
38
38
39
p . initialize = function ( cm , highlighter ) {
39
40
this . cm = cm ;
@@ -43,20 +44,35 @@ SOFTWARE.
43
44
this . tooltip = Tooltip . add ( cm . display . lineDiv ) ;
44
45
this . tooltip . on ( "mousemove" , this . onMouseMove , this ) ;
45
46
this . tooltip . on ( "mouseout" , this . onMouseOut , this ) ;
47
+
48
+ cm . on ( "mousedown" , $ . bind ( this , this . onMouseDown ) ) ;
49
+ } ;
50
+
51
+ p . onMouseDown = function ( evt ) {
52
+ if ( evt . which != 1 ) { return ; }
53
+ this . onMouseMove ( ) ; // clear current
54
+ this . isMouseDown = true ;
55
+ ( window . addEventListener ? window : document ) . addEventListener ( "mouseup" , $ . bind ( this , this . onMouseUp ) ) ;
56
+ } ;
57
+
58
+ p . onMouseUp = function ( evt ) {
59
+ if ( evt . which != 1 ) { return ; }
60
+ this . isMouseDown = false ;
46
61
} ;
47
62
48
63
p . onMouseMove = function ( evt ) {
64
+ if ( this . isMouseDown ) { return ; }
49
65
var index , cm = this . cm , token = this . token , target = null ;
50
66
51
- if ( token && ( index = CMUtils . getCharIndexAt ( cm , evt . clientX , evt . clientY + window . pageYOffset ) ) != null ) {
67
+ if ( evt && token && ( index = CMUtils . getCharIndexAt ( cm , evt . clientX , evt . clientY + window . pageYOffset ) ) != null ) {
52
68
index -= this . offset ;
53
69
while ( token ) {
54
70
if ( index >= token . i && index < token . end ) { target = token ; break ; }
55
71
token = token . next ;
56
72
}
57
73
}
58
74
if ( target && target . proxy ) { target = target . proxy ; }
59
-
75
+
60
76
this . highlighter . selectToken ( target ) ;
61
77
var rect = ( index != null ) && CMUtils . getCharRect ( cm , index ) ;
62
78
if ( rect ) { rect . right = rect . left = evt . clientX ; }
0 commit comments