@@ -97,7 +97,7 @@ var CodeMirror = (function() {
9797 connect ( wrapper , "dragenter" , function ( e ) { e . stop ( ) ; } ) ;
9898 connect ( wrapper , "dragover" , function ( e ) { e . stop ( ) ; } ) ;
9999 connect ( wrapper , "drop" , operation ( onDrop ) ) ;
100- connect ( wrapper , "paste" , function ( ) { input . focus ( ) ; fastPoll ( ) ; } ) ;
100+ connect ( wrapper , "paste" , function ( ) { focusInput ( ) ; fastPoll ( ) ; } ) ;
101101 connect ( input , "paste" , function ( ) { fastPoll ( ) ; } ) ;
102102 connect ( input , "cut" , function ( ) { fastPoll ( ) ; } ) ;
103103
@@ -115,11 +115,12 @@ var CodeMirror = (function() {
115115 setValue : operation ( setValue ) ,
116116 getSelection : getSelection ,
117117 replaceSelection : operation ( replaceSelection ) ,
118- focus : function ( ) { input . focus ( ) ; onFocus ( ) ; fastPoll ( ) ; } ,
118+ focus : function ( ) { focusInput ( ) ; onFocus ( ) ; fastPoll ( ) ; } ,
119119 setOption : function ( option , value ) {
120120 options [ option ] = value ;
121121 if ( option == "lineNumbers" || option == "gutter" ) gutterChanged ( ) ;
122122 else if ( option == "mode" || option == "indentUnit" ) loadMode ( ) ;
123+ else if ( option == "readOnly" && value == "nocursor" ) input . blur ( ) ;
123124 } ,
124125 getOption : function ( option ) { return options [ option ] ; } ,
125126 undo : operation ( undo ) ,
@@ -223,7 +224,7 @@ var CodeMirror = (function() {
223224 // And then we have to see if it's a drag event, in which case
224225 // the dragged-over text must be selected.
225226 function end ( ) {
226- input . focus ( ) ;
227+ focusInput ( ) ;
227228 updateInput = true ;
228229 move ( ) ; up ( ) ;
229230 }
@@ -345,6 +346,7 @@ var CodeMirror = (function() {
345346 }
346347
347348 function onFocus ( ) {
349+ if ( options . readOnly == "nocursor" ) return ;
348350 if ( ! focused && options . onFocus ) options . onFocus ( instance ) ;
349351 focused = true ;
350352 slowPoll ( ) ;
@@ -614,6 +616,9 @@ var CodeMirror = (function() {
614616 editing = { text : text , from : from , to : to , start : startch , end : endch } ;
615617 setSelRange ( input , startch , reducedSelection ? startch : endch ) ;
616618 }
619+ function focusInput ( ) {
620+ if ( options . readOnly != "nocursor" ) input . focus ( ) ;
621+ }
617622
618623 function scrollCursorIntoView ( ) {
619624 var cursor = localCoords ( sel . inverted ? sel . from : sel . to ) ;
@@ -1127,7 +1132,7 @@ var CodeMirror = (function() {
11271132 "px; left: " + ( e . pageX ( ) - 1 ) + "px; z-index: 1000; background: white; " +
11281133 "border-width: 0; outline: none; overflow: hidden;" ;
11291134 var val = input . value = getSelection ( ) ;
1130- input . focus ( ) ;
1135+ focusInput ( ) ;
11311136 setSelRange ( input , 0 , input . value . length ) ;
11321137 if ( gecko ) e . stop ( ) ;
11331138 leaveInputAlone = true ;
0 commit comments