@@ -1893,6 +1893,7 @@ var CodeMirror = (function() {
18931893
18941894 var gecko = / g e c k o \/ \d { 7 } / i. test ( navigator . userAgent ) ;
18951895 var ie = / M S I E \d / . test ( navigator . userAgent ) ;
1896+ var safari = / A p p l e C o m p u t e r / . test ( navigator . vendor ) ;
18961897
18971898 var lineSep = "\n" ;
18981899 // Feature-detect whether newlines in textareas are converted to \r\n
@@ -1993,10 +1994,26 @@ var CodeMirror = (function() {
19931994 try { return { start : te . selectionStart , end : te . selectionEnd } ; }
19941995 catch ( e ) { return null ; }
19951996 } ;
1996- var setSelRange = function ( te , start , end ) {
1997- try { te . setSelectionRange ( start , end ) ; }
1998- catch ( e ) { } // Fails on Firefox when textarea isn't part of the document
1999- } ;
1997+ if ( safari )
1998+ // On Safari, selection set with setSelectionRange are in a sort
1999+ // of limbo wrt their anchor. If you press shift-left in them,
2000+ // the anchor is put at the end, and the selection expanded to
2001+ // the left. If you press shift-right, the anchor ends up at the
2002+ // front. This is not what CodeMirror wants, so it does a
2003+ // spurious modify() call to get out of limbo.
2004+ var setSelRange = function ( te , start , end ) {
2005+ if ( start == end )
2006+ te . setSelectionRange ( start , end ) ;
2007+ else {
2008+ te . setSelectionRange ( start , end - 1 ) ;
2009+ window . getSelection ( ) . modify ( "expand" , "forward" , "character" ) ;
2010+ }
2011+ } ;
2012+ else
2013+ var setSelRange = function ( te , start , end ) {
2014+ try { te . setSelectionRange ( start , end ) ; }
2015+ catch ( e ) { } // Fails on Firefox when textarea isn't part of the document
2016+ } ;
20002017 }
20012018 // IE model. Don't ask.
20022019 else {
0 commit comments