Anonymous avatar Anonymous committed 8fb3790

Add pollForIME option

Thanks to Taku Amano for doing most of the research for this.

Comments (0)

Files changed (2)

lib/codemirror.js

     operation(function(){setValue(options.value || ""); updateInput = false;})();
     var history = new History();
 
+    var slowPollInterval = 2000;
+    // Gecko and Opera Linux do not reliably fire any event when starting an IME compose
+    var alwaysPollForIME = (!win && !mac) && (gecko || window.opera);
+    if (options.pollForIME && alwaysPollForIME) slowPollInterval = 50;
+    function keyMightStartIME(keyCode) {
+      return (win && ((gecko && keyCode == 229) || (window.opera && keyCode == 197))) || (mac && gecko);
+    }
+
     // Register our event handlers.
     connect(scroller, "mousedown", operation(onMouseDown));
     connect(scroller, "dblclick", operation(onDoubleClick));
         else if (option == "readOnly" && value == "nocursor") input.blur();
         else if (option == "theme") scroller.className = scroller.className.replace(/cm-s-\w+/, "cm-s-" + value);
         else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)();
+        else if (option == "pollForIME" && alwaysPollForIME) slowPollInterval = value ? 50 : 2000;
       },
       getOption: function(option) {return options[option];},
       undo: operation(undo),
       // Don't save the key as a movementkey unless it had a modifier
       if (!mod && !e.altKey) curKeyId = null;
       fastPoll(curKeyId);
+
+      if (options.pollForIME && keyMightStartIME(code)) slowPollInterval = 50;
     }
     function onKeyUp(e) {
       if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
         updateInput = true;
       }
       if (e.keyCode == 16) shiftSelecting = null;
+
+      if (slowPollInterval < 2000 && !alwaysPollForIME) slowPollInterval = 2000;
     }
     function onKeyPress(e) {
       if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
     var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
     function slowPoll() {
       if (pollingFast) return;
-      poll.set(2000, function() {
+      poll.set(slowPollInterval, function() {
         startOperation();
         readInput();
         if (focused) slowPoll();
     workDelay: 200,
     undoDepth: 40,
     tabindex: null,
+    pollForIME: false,
     document: window.document
   };
 
 
   var tabSize = 8;
   var mac = /Mac/.test(navigator.platform);
+  var win = /Win/.test(navigator.platform);
   var movementKeys = {};
   for (var i = 35; i <= 40; ++i)
     movementKeys[i] = movementKeys["c" + i] = true;
       non-whitespace character (unless already there) or to the start
       of the line. On by default.</dd>
 
+      <dt id="option_pollForIME"><code>pollForIME (boolean)</code></dt>
+      <dd>When on (off by default), this will cause CodeMirror to poll
+      for input more agressively in an attempt to respond quickly to
+      IME (composed character) input.</dd>
+
       <dt id="option_lineWrapping"><code>lineWrapping (boolean)</code></dt>
       <dd>Whether CodeMirror should scroll or wrap for long lines.
       Defaults to <code>false</code> (scroll).</dd>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.