Created
June 10, 2011 09:42
-
-
Save mash/1018553 to your computer and use it in GitHub Desktop.
codemirror editor.js fix for ime mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/js/editor.js b/js/editor.js | |
| index 4475579..caed9c9 100644 | |
| --- a/js/editor.js | |
| +++ b/js/editor.js | |
| @@ -755,7 +755,7 @@ var Editor = (function(){ | |
| return; | |
| } | |
| - var code = event.keyCode; | |
| + var code = this.lastKeyDownCode = event.keyCode; | |
| // Don't scan when the user is typing. | |
| this.delayScanning(); | |
| // Schedule a paren-highlight event, if configured. | |
| @@ -803,14 +803,14 @@ var Editor = (function(){ | |
| } | |
| else if (event.metaKey && !event.shiftKey && (code == 37 || code == 39)) { // Meta-left/right | |
| var cursor = select.selectionTopNode(this.container); | |
| - if (cursor === false || !this.container.firstChild) return; | |
| - | |
| - if (code == 37) select.focusAfterNode(startOfLine(cursor), this.container); | |
| - else { | |
| - var end = endOfLine(cursor, this.container); | |
| - select.focusAfterNode(end ? end.previousSibling : this.container.lastChild, this.container); | |
| + if (cursor !== false && this.container.firstChild) { | |
| + if (code == 37) select.focusAfterNode(startOfLine(cursor), this.container); | |
| + else { | |
| + var end = endOfLine(cursor, this.container); | |
| + select.focusAfterNode(end ? end.previousSibling : this.container.lastChild, this.container); | |
| + } | |
| + event.stop(); | |
| } | |
| - event.stop(); | |
| } | |
| else if ((event.ctrlKey || event.metaKey) && !event.altKey) { | |
| if ((event.shiftKey && code == 90) || code == 89) { // shift-Z, Y | |
| @@ -829,11 +829,13 @@ var Editor = (function(){ | |
| this.reroutePasteEvent(); | |
| } | |
| } | |
| + this.keyUpOrPressAfterLastKeyDown = false; | |
| }, | |
| // Check for characters that should re-indent the current line, | |
| // and prevent Opera from handling enter and tab anyway. | |
| keyPress: function(event) { | |
| + this.keyUpOrPressAfterLastKeyDown = true; | |
| var electric = Editor.Parser.electricChars, self = this; | |
| // Hack for Opera, and Firefox on OS X, in which stopping a | |
| // keydown event does not prevent the associated keypress event | |
| @@ -853,6 +855,7 @@ var Editor = (function(){ | |
| // Mark the node at the cursor dirty when a non-safe key is | |
| // released. | |
| keyUp: function(event) { | |
| + this.keyUpOrPressAfterLastKeyDown = true; | |
| this.cursorActivity(isSafeKey(event.keyCode)); | |
| }, | |
| @@ -1279,6 +1282,12 @@ var Editor = (function(){ | |
| } | |
| }, | |
| + isIMEOn: function() { | |
| + // chrome: keyDown keyCode is 229 while IME on | |
| + // firefox: no keyUps or keyPresses fires after first keyDown while IME on | |
| + return this.lastKeyDownCode == 229 || this.keyUpOrPressAfterLastKeyDown === false; | |
| + }, | |
| + | |
| // The function that does the actual highlighting/colouring (with | |
| // help from the parser and the DOM normalizer). Its interface is | |
| // rather overcomplicated, because it is used in different | |
| @@ -1298,7 +1307,7 @@ var Editor = (function(){ | |
| var container = this.container, self = this, active = this.options.activeTokens; | |
| var endTime = (typeof target == "number" ? target : null); | |
| - if (!container.firstChild) | |
| + if (!container.firstChild || this.isIMEOn()) | |
| return false; | |
| // Backtrack to the first node before from that has a partial | |
| // parse stored. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment