@ -12,6 +12,7 @@
var IPython = ( function ( IPython ) {
// TextCell base class
var key = IPython . utils . keycodes ;
var TextCell = function ( ) {
this . code _mirror _mode = this . code _mirror _mode || 'htmlmixed' ;
@ -269,6 +270,36 @@ var IPython = (function (IPython) {
} ;
RawCell . prototype . handle _codemirror _keyevent = function ( editor , event ) {
// This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
var that = this ;
if ( event . which === key . UPARROW && event . type === 'keydown' ) {
// If we are not at the top, let CM handle the up arrow and
// prevent the global keydown handler from handling it.
if ( ! that . at _top ( ) ) {
event . stop ( ) ;
return false ;
} else {
return true ;
} ;
} else if ( event . which === key . DOWNARROW && event . type === 'keydown' ) {
// If we are not at the bottom, let CM handle the down arrow and
// prevent the global keydown handler from handling it.
if ( ! that . at _bottom ( ) ) {
event . stop ( ) ;
return false ;
} else {
return true ;
} ;
} ;
return false ;
} ;
RawCell . prototype . select = function ( ) {
IPython . Cell . prototype . select . apply ( this ) ;
this . code _mirror . refresh ( ) ;
@ -278,7 +309,7 @@ var IPython = (function (IPython) {
RawCell . prototype . at _top = function ( ) {
var cursor = this . code _mirror . getCursor ( ) ;
if ( cursor . line === 0 ) {
if ( cursor . line === 0 && cursor . ch === 0 ) {
return true ;
} else {
return false ;
@ -288,7 +319,7 @@ var IPython = (function (IPython) {
RawCell . prototype . at _bottom = function ( ) {
var cursor = this . code _mirror . getCursor ( ) ;
if ( cursor . line === ( this . code _mirror . lineCount ( ) - 1 ) ) {
if ( cursor . line === ( this . code _mirror . lineCount ( ) - 1 ) && cursor . ch === this . code _mirror . getLine ( cursor . line ) . length ) {
return true ;
} else {
return false ;