@@ -1258,7 +1258,7 @@ window.CodeMirror = (function() {
12581258 on ( d . scroller , "mousedown" , operation ( cm , onMouseDown ) ) ;
12591259 on ( d . scroller , "dblclick" , operation ( cm , e_preventDefault ) ) ;
12601260 on ( d . lineSpace , "selectstart" , function ( e ) {
1261- if ( ! mouseEventInWidget ( d , e ) ) e_preventDefault ( e ) ;
1261+ if ( ! eventInWidget ( d , e ) ) e_preventDefault ( e ) ;
12621262 } ) ;
12631263 // Gecko browsers fire contextmenu *after* opening the menu, at
12641264 // which point we can't mess with it anymore. Context menu is
@@ -1313,7 +1313,11 @@ window.CodeMirror = (function() {
13131313 on ( d . scroller , "dragover" , drag_ ) ;
13141314 on ( d . scroller , "drop" , operation ( cm , onDrop ) ) ;
13151315 }
1316- on ( d . scroller , "paste" , function ( ) { focusInput ( cm ) ; fastPoll ( cm ) ; } ) ;
1316+ on ( d . scroller , "paste" , function ( ) {
1317+ if ( eventInWidget ( d , e ) ) return ;
1318+ focusInput ( cm ) ;
1319+ fastPoll ( cm ) ;
1320+ } ) ;
13171321 on ( d . input , "paste" , function ( ) {
13181322 d . pasteIncoming = true ;
13191323 fastPoll ( cm ) ;
@@ -1337,7 +1341,7 @@ window.CodeMirror = (function() {
13371341 } ) ;
13381342 }
13391343
1340- function mouseEventInWidget ( display , e ) {
1344+ function eventInWidget ( display , e ) {
13411345 for ( var n = e_target ( e ) ; n != display . wrapper ; n = n . parentNode )
13421346 if ( / \b C o d e M i r r o r - (?: l i n e ) ? w i d g e t \b / . test ( n . className ) ||
13431347 n . parentNode == display . sizer && n != display . mover ) return true ;
@@ -1362,7 +1366,7 @@ window.CodeMirror = (function() {
13621366 var cm = this , display = cm . display , view = cm . view , sel = view . sel , doc = view . doc ;
13631367 sel . shift = e_prop ( e , "shiftKey" ) ;
13641368
1365- if ( mouseEventInWidget ( display , e ) ) {
1369+ if ( eventInWidget ( display , e ) ) {
13661370 if ( ! webkit ) {
13671371 display . scroller . draggable = false ;
13681372 setTimeout ( function ( ) { display . scroller . draggable = true ; } , 100 ) ;
@@ -1498,7 +1502,8 @@ window.CodeMirror = (function() {
14981502
14991503 function onDrop ( e ) {
15001504 var cm = this ;
1501- if ( cm . options . onDragEvent && cm . options . onDragEvent ( cm , addStop ( e ) ) ) return ;
1505+ if ( eventInWidget ( cm . display , e ) || ( cm . options . onDragEvent && cm . options . onDragEvent ( cm , addStop ( e ) ) ) )
1506+ return ;
15021507 e_preventDefault ( e ) ;
15031508 var pos = posFromMouse ( cm , e , true ) , files = e . dataTransfer . files ;
15041509 if ( ! pos || isReadOnly ( cm ) ) return ;
@@ -1567,6 +1572,8 @@ window.CodeMirror = (function() {
15671572 }
15681573
15691574 function onDragStart ( cm , e ) {
1575+ if ( isInWidget ( cm . display , e ) ) return ;
1576+
15701577 var txt = cm . getSelection ( ) ;
15711578 e . dataTransfer . setData ( "Text" , txt ) ;
15721579
@@ -1815,7 +1822,10 @@ window.CodeMirror = (function() {
18151822
18161823 var detectingSelectAll ;
18171824 function onContextMenu ( cm , e ) {
1818- var display = cm . display , sel = cm . view . sel ;
1825+ var display = cm . display ;
1826+ if ( eventInWidget ( display , e ) ) return ;
1827+
1828+ var sel = cm . view . sel ;
18191829 var pos = posFromMouse ( cm , e ) , scrollPos = display . scroller . scrollTop ;
18201830 if ( ! pos || opera ) return ; // Opera is difficult.
18211831 if ( posEq ( sel . from , sel . to ) || posLess ( pos , sel . from ) || ! posLess ( pos , sel . to ) )
0 commit comments