title: Detect focus of codemirror editor
body: <p>I am using codemirror in a webapp I am creating and I have several editors on the page. There are undo and redo buttons as well and they do work. However I can only set one editor to undo unless I use an if statement to determine which one is focussed and then apply the undo or redo function to its corresponding textbox. I have tried a few variations in both jQuery and JavaScript but to no avail. This is one of the code blocks I am attempting to get to work. The actual variable that holds the codemirror setup is called "codeeditor1", "#editor1" is the id of the textbox.</p>
  
  <pre><code>if ($("#editor1").is(':focus')) {
    undo.addEventListener('click', function() {
        codeeditor1.undo();
    }, false);
    redo.addEventListener('click', function() {
        codeeditor1.redo();
    }, false);
  }
  </code></pre>
  
  <p>I also tried this according to the documentation of the method "cm.hasFocus()" = boolean.</p>
  
  <pre><code>if (codeeditor1.hasFocus() == true) {
      undo.addEventListener('click', function() {
          codeeditor1.undo();
      }, false);
      redo.addEventListener('click', function() {
          codeeditor1.redo();
      }, false);
  }
  </code></pre>
  
  <p>I have now also tried this for the sake of logical code placement but still no luck with it. Perhaps it is a bug in the method of codemirror?</p>
  
  <pre><code>undo.addEventListener('click', function() {
      if (codeeditor1.hasFocus() == true) {
          codeeditor1.undo();
      }
  }, false);
  
  redo.addEventListener('click', function() {
      if (codeeditor1.hasFocus() == true) {
          codeeditor1.redo();
      }
  }, false);
  </code></pre>