Permalink
Browse files

Don't autofocus on mobile devices

  • Loading branch information...
1 parent 5497f68 commit aa347a319fe938f1aed0f27439649ff24c6d2565 @marijnh marijnh committed Dec 10, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/codemirror.js
View
@@ -21,6 +21,8 @@ window.CodeMirror = (function() {
var phantom = /PhantomJS/.test(navigator.userAgent);
var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
+ // This is woefully incomplete. Suggestions for alternative methods welcome.
+ var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent);
var mac = ios || /Mac/.test(navigator.platform);
// Optimize some code when these features are not used
@@ -40,7 +42,7 @@ window.CodeMirror = (function() {
var display = this.display = makeDisplay(place);
display.wrapper.CodeMirror = this;
updateGutters(this);
- if (options.autofocus) focusInput(this);
+ if (options.autofocus && !mobile) focusInput(this);
this.view = makeView(new BranchChunk([new LeafChunk([makeLine("", null, textHeight(display))])]));
this.nextOpId = 0;
@@ -60,7 +62,7 @@ window.CodeMirror = (function() {
// IE throws unspecified error in certain cases, when
// trying to access activeElement before onload
var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
- if (hasFocus || options.autofocus) setTimeout(bind(onFocus, this), 20);
+ if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
else onBlur(this);
operation(this, function() {

0 comments on commit aa347a3

Please sign in to comment.