@ -57,42 +57,9 @@ var IPython = (function (IPython) {
that . select _next ( ) ;
} ;
} else if ( event . which === 13 && event . shiftKey ) {
// The focus is not quite working here.
var cell = that . selected _cell ( ) ;
var cell _index = that . find _cell _index ( cell ) ;
// TODO: the logic here needs to be moved into appropriate
// methods of Notebook.
if ( cell instanceof IPython . CodeCell ) {
event . preventDefault ( ) ;
cell . clear _output ( ) ;
var code = cell . get _code ( ) ;
if ( that . notebook _load _re . test ( code ) ) {
var code _parts = code . split ( ' ' ) ;
if ( code _parts . length === 3 ) {
that . load _notebook ( code _parts [ 2 ] ) ;
} ;
} else if ( that . notebook _save _re . test ( code ) ) {
var code _parts = code . split ( ' ' ) ;
if ( code _parts . length === 3 ) {
that . save _notebook ( code _parts [ 2 ] ) ;
} else {
that . save _notebook ( )
} ;
} else {
var msg _id = that . kernel . execute ( cell . get _code ( ) ) ;
that . msg _cell _map [ msg _id ] = cell . cell _id ;
} ;
} else if ( cell instanceof IPython . TextCell ) {
event . preventDefault ( ) ;
cell . render ( ) ;
}
if ( cell _index === ( that . ncells ( ) - 1 ) ) {
that . insert _code _cell _after ( ) ;
// If we are adding a new cell at the end, scroll down to show it.
that . scroll _to _bottom ( ) ;
} else {
that . select ( cell _index + 1 ) ;
} ;
console . log ( 'Entering execute' ) ;
that . execute _selected _cell ( true ) ;
console . log ( 'Leaving execute' ) ;
} ;
} ) ;
@ -489,6 +456,54 @@ var IPython = (function (IPython) {
} ;
Notebook . prototype . execute _selected _cell = function ( add _new ) {
if ( add _new === undefined ) { add _new = true ; } ;
var that = this ;
var cell = that . selected _cell ( ) ;
var cell _index = that . find _cell _index ( cell ) ;
// TODO: the logic here needs to be moved into appropriate
// methods of Notebook.
if ( cell instanceof IPython . CodeCell ) {
cell . clear _output ( ) ;
var code = cell . get _code ( ) ;
if ( that . notebook _load _re . test ( code ) ) {
var code _parts = code . split ( ' ' ) ;
if ( code _parts . length === 3 ) {
that . load _notebook ( code _parts [ 2 ] ) ;
} ;
} else if ( that . notebook _save _re . test ( code ) ) {
var code _parts = code . split ( ' ' ) ;
if ( code _parts . length === 3 ) {
that . save _notebook ( code _parts [ 2 ] ) ;
} else {
that . save _notebook ( )
} ;
} else {
var msg _id = that . kernel . execute ( cell . get _code ( ) ) ;
that . msg _cell _map [ msg _id ] = cell . cell _id ;
} ;
} else if ( cell instanceof IPython . TextCell ) {
cell . render ( ) ;
}
if ( ( cell _index === ( that . ncells ( ) - 1 ) ) && add _new ) {
that . insert _code _cell _after ( ) ;
// If we are adding a new cell at the end, scroll down to show it.
that . scroll _to _bottom ( ) ;
} else {
that . select ( cell _index + 1 ) ;
} ;
} ;
Notebook . prototype . execute _all _cells = function ( ) {
var ncells = this . ncells ( ) ;
for ( var i = 0 ; i < ncells ; i ++ ) {
this . select ( i ) ;
this . execute _selected _cell ( false ) ;
} ;
this . scroll _to _bottom ( ) ;
} ;
// Persistance and loading