Skip to content

Commit

Permalink
Handles CTRL-Enter event to save in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
christian studer committed Nov 12, 2014
1 parent d742dc2 commit 52ec63b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/scripts/editor.js
Expand Up @@ -124,14 +124,15 @@ var dw_editor = {
* Listens to all key inputs and handle indentions
* of lists and code blocks
*
* Currently handles space, backspce and enter presses
* Currently handles space, backspace, enter and
* ctrl-enter presses
*
* @author Andreas Gohr <andi@splitbrain.org>
* @fixme handle tabs
* @param event e - the key press event object
*/
keyHandler: function(e){
if(jQuery.inArray(e.keyCode,[8, 13, 32]) === -1) {
if(jQuery.inArray(e.keyCode,[8, 10, 13, 32]) === -1) {
return;
}
var selection = DWgetSelection(this);
Expand All @@ -143,7 +144,12 @@ var dw_editor = {
search.lastIndexOf("\r")); //IE workaround
search = search.substr(linestart);

if(e.keyCode == 13){ // Enter
if((e.keyCode == 13 || e.keyCode == 10) && e.ctrlKey) { // Ctrl-Enter (With Chrome workaround)
// Submit current edit
jQuery('input#edbtn__save').click();
e.preventDefault(); // prevent enter key
return false;
}else if(e.keyCode == 13){ // Enter
// keep current indention for lists and code
var match = search.match(/(\n +([\*-] ?)?)/);
if(match){
Expand Down

0 comments on commit 52ec63b

Please sign in to comment.