Fix save switch to command mode after shortcut

When triggering actions with button one have to refocus the notebook
cell. Though with keyboard shortcut, you don't want cell to switch to
command mode.
This commit is contained in:
Matthias Bussonnier 2015-03-11 16:37:23 -07:00
parent c37f51eac2
commit 0408e7e4e4
3 changed files with 17 additions and 1 deletions

View File

@ -381,7 +381,7 @@ define(function(require){
if(event){
event.preventDefault();
}
env.notebook.focus_cell();
env.notebook.ensure_focused();
return false;
}
},

View File

@ -375,6 +375,12 @@ define([
return false;
}
};
Cell.prototype.ensure_focused = function() {
if(this.element !== document.activeElement && !this.code_mirror.hasFocus()){
this.focus_cell();
}
}
/**
* Focus the cell in the DOM sense

View File

@ -695,6 +695,16 @@ define(function (require) {
cell.focus_editor();
}
};
/**
* Ensure either cell, or codemirror is focused. Is none
* is focused, focus the cell.
*/
Notebook.prototype.ensure_focused = function(){
var cell = this.get_selected_cell();
if (cell === null) {return;} // No cell is selected
cell.ensure_focused();
}
/**
* Focus the currently selected cell.