Skip to content

Commit

Permalink
properly work around flaky enter behaviour in Opera
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Feb 8, 2011
1 parent 6028bde commit c9dd74e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/codemirror.js
Expand Up @@ -364,6 +364,7 @@ var CodeMirror = (function() {
connect(window, "resize", updateDisplay);
connect(input, "keyup", operation(onKeyUp));
connect(input, "keydown", operation(onKeyDown));
connect(input, "keypress", operation(onKeyPress));
connect(input, "focus", onFocus);
connect(input, "blur", onBlur);

Expand Down Expand Up @@ -471,6 +472,7 @@ var CodeMirror = (function() {
if (code == 33 || code == 34) {scrollPage(code == 34); done = true;} // page up/down
else if (ctrl && (code == 36 || code == 35)) {scrollEnd(code == 36); done = true;} // ctrl-home/end
else if (ctrl && code == 65) {selectAll(); done = true;} // ctrl-a
// TODO just use shiftKey property of key events. less fragile
else if (code == 16) {shiftSelecting = sel.inverted ? sel.to : sel.from;} // shift
else if (!options.readOnly) {
if (!ctrl && code == 13) {handleEnter(); done = true;} // enter
Expand Down Expand Up @@ -498,6 +500,10 @@ var CodeMirror = (function() {
if (e.e.keyCode == 16)
shiftSelecting = null;
}
function onKeyPress(e) {
var code = e.e.keyCode;
if (code == 13 || (code == 9 && options.tabMode != "default")) e.stop();
}

function onFocus() {
focused = true;
Expand Down Expand Up @@ -1226,7 +1232,7 @@ var CodeMirror = (function() {
if (changes.length) updateDisplay(changes);
if (selectionChanged) {updateCursor(); restartBlink();}
if (updateInput === true || (updateInput !== false && selectionChanged))
setTimeout(prepareInput, 20);
prepareInput();

if (selectionChanged && options.onCursorActivity)
options.onCursorActivity(instance);
Expand Down

0 comments on commit c9dd74e

Please sign in to comment.