@ -55,12 +55,6 @@ var IPython = (function (IPython) {
this . notebook _name _blacklist _re = /[\/\\:]/ ;
this . nbformat = 3 ; // Increment this when changing the nbformat
this . nbformat _minor = 0 ; // Increment this when changing the nbformat
// This is a list of callbacks that are called when a cell's textual
// region is unfocused. If one of the callbacks returns True, the cell
// unfocus event will be ignored. Callbacks will be passed one argument,
// the cell instance.
this . cancel _unfocus _callbacks = [ ] ;
this . style ( ) ;
this . create _elements ( ) ;
this . bind _events ( ) ;
@ -122,11 +116,11 @@ var IPython = (function (IPython) {
} ) ;
$ ( [ IPython . events ] ) . on ( 'focus_text.Cell' , function ( event , data ) {
that . handle _cell _text _focus ( that. find _cell _index ( data. cell ) ) ;
that . handle _cell _text _focus ( data. cell ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'blur_text.Cell' , function ( event , data ) {
that . handle _cell _text _blur ( that. find _cell _index ( data. cell ) ) ;
that . handle _cell _text _blur ( data. cell ) ;
} ) ;
$ ( [ IPython . events ] ) . on ( 'status_autorestarting.Kernel' , function ( ) {
@ -522,7 +516,6 @@ var IPython = (function (IPython) {
} ;
Notebook . prototype . command _mode = function ( ) {
console . log ( 'notebook command_mode()' ) ;
// Make sure there isn't an edit mode cell lingering around.
var cell = this . get _cell ( this . get _edit _index ( ) ) ;
@ -540,32 +533,23 @@ var IPython = (function (IPython) {
} ;
Notebook . prototype . edit _mode = function ( index ) {
console . log ( 'notebook edit_mode()' ) ;
// Either use specified index or selected cell's index.
// Must explictly check for undefined CBool(0) = false.
var focus _editor = false ;
if ( index === undefined ) {
index = this . get _selected _index ( ) ;
focus _editor = true ;
} else {
this . select ( index ) ;
}
var cell = this . get _cell ( index ) ;
// Make sure the cell exists.
var cell = this . get _cell ( index ) ;
if ( cell === null ) { return ; }
// If another cell is currently in edit mode set it to command mode.
var edit _index = this . get _edit _index ( index ) ;
if ( edit _index !== null ) { // Must explictly check for null CBool(0) = false.
var edit _cell = this . get _cell ( edit _index ) ;
if ( edit _cell ) {
edit _cell . command _mode ( ) ;
}
}
// Set the cell to edit mode and notify the keyboard manager if this
// is a change of mode for the notebook as a whole.
if ( this . get _selected _index ( ) !== index ) {
this . select ( index ) ;
}
cell . edit _mode ( ) ;
cell . edit _mode ( focus _editor ) ;
if ( this . mode !== 'edit' ) {
this . mode = 'edit' ;
$ ( [ IPython . events ] ) . trigger ( 'edit_mode.Notebook' ) ;
@ -579,30 +563,20 @@ var IPython = (function (IPython) {
cell . focus _cell ( ) ;
} ;
Notebook . prototype . handle _cell _text _focus = function ( index ) {
this . edit _mode ( index ) ;
Notebook . prototype . handle _cell _text _focus = function ( cell ) {
console . log ( 'notebook.handle_cell_text_focus' , cell ) ;
this . edit _mode ( this . find _cell _index ( cell ) ) ;
} ;
Notebook . prototype . handle _cell _text _blur = function ( index ) {
var cell = this . get _cell ( index ) ;
if ( ! cell ) { return ; }
Notebook . prototype . handle _cell _text _blur = function ( cell ) {
// In Firefox the focus event is called before the blur event. In
// other words, two cells elements may be focused at any given time.
// This has been witnessed on Win7 x64 w/ FF 25&26.
console . log ( 'notebook.handle_cell_text_blur' , cell ) ;
// Check if this unfocus event is legit.
if ( ! this . should _cancel _unfocus ( cell ) ) {
// In Firefox the focus event is called before the blur event. In
// other words, two cells elements may be focused at any given time.
// This has been witnessed on Win7 x64 w/ FF 25. Here we only put the
// entire notebook in command mode iff the cell textbox being blured is
// the one that is currently in edit mode. Otherwise, we assume the
// event order has been reversed and we just put this particular cell
// in command mode.
if ( index === this . get _edit _index ( index ) ) {
console . log ( 'full command_mode' ) ;
this . command _mode ( ) ;
} else {
console . log ( 'cell command_mode' ) ;
cell . command _mode ( ) ;
}
this . command _mode ( ) ;
}
} ;
@ -612,18 +586,9 @@ var IPython = (function (IPython) {
// If the tooltip is visible, ignore the unfocus.
var tooltip _visible = IPython . tooltip && IPython . tooltip . is _visible ( ) ;
if ( tooltip _visible ) { return true ; }
// Try user registered callbacks.
for ( var i = 0 ; i < this . cancel _unfocus _callbacks . length ; i ++ ) {
if ( this . cancel _unfocus _callbacks [ i ] ( cell ) ) { return true ; }
}
// Check the cell's should_cancel_unfocus method.
if ( cell . should _cancel _unfocus !== undefined && cell . should _cancel _unfocus ( ) ) {
return true ;
} else {
return false ;
}
return ( cell . should _cancel _unfocus !== undefined && cell . should _cancel _unfocus ( ) ) ;
} ;
// Cell movement
@ -1482,7 +1447,6 @@ var IPython = (function (IPython) {
var cell = this . get _selected _cell ( ) ;
var cell _index = this . find _cell _index ( cell ) ;
console . log ( 'execute cell command_mode' ) ;
cell . execute ( ) ;
cell . focus _cell ( ) ;
this . command _mode ( ) ;
@ -1503,16 +1467,14 @@ var IPython = (function (IPython) {
// If we are at the end always insert a new cell and return
if ( cell _index === ( this . ncells ( ) - 1 ) ) {
this . insert _cell _below ( 'code' ) ;
this . select ( cell _index + 1 ) ;
this . edit _mode ( ) ;
this . edit _mode ( cell _index + 1 ) ;
this . scroll _to _bottom ( ) ;
this . set _dirty ( true ) ;
return ;
}
this . insert _cell _below ( 'code' ) ;
this . select ( cell _index + 1 ) ;
this . edit _mode ( ) ;
this . edit _mode ( cell _index + 1 ) ;
this . set _dirty ( true ) ;
} ;
@ -1531,8 +1493,7 @@ var IPython = (function (IPython) {
// If we are at the end always insert a new cell and return
if ( cell _index === ( this . ncells ( ) - 1 ) ) {
this . insert _cell _below ( 'code' ) ;
this . select ( cell _index + 1 ) ;
this . edit _mode ( ) ;
this . edit _mode ( cell _index + 1 ) ;
this . scroll _to _bottom ( ) ;
this . set _dirty ( true ) ;
return ;
@ -2008,8 +1969,7 @@ var IPython = (function (IPython) {
console . log ( 'load notebook success' ) ;
if ( this . ncells ( ) === 0 ) {
this . insert _cell _below ( 'code' ) ;
this . select ( 0 ) ;
this . edit _mode ( ) ;
this . edit _mode ( 0 ) ;
} else {
this . select ( 0 ) ;
this . command _mode ( ) ;
@ -2369,3 +2329,4 @@ var IPython = (function (IPython) {
return IPython ;
} ( IPython ) ) ;