Adding new node via enter after current block, even if no cursor is active
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 9 Oct 2013 14:25:23 +0000 (16:25 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 9 Oct 2013 14:25:23 +0000 (16:25 +0200)
src/editor/modules/documentCanvas/canvas/keyboard.js

index a6f52cf..57a245e 100644 (file)
@@ -44,6 +44,16 @@ handlers.push({key: KEYS.ENTER,
             position = cursor.getPosition(),
             element = position.element;
 
             position = cursor.getPosition(),
             element = position.element;
 
+        if(Object.keys(cursor.getPosition()).length === 0) {
+            var currentElement = canvas.getCurrentNodeElement();
+            if(currentElement) {
+                var added = currentElement.after({tag: currentElement.getWlxmlTag() || 'div', klass: currentElement.getWlxmlClass() || 'p'});
+                added.append({text:''});
+                canvas.setCurrentElement(added, {caretTo: 'start'});
+            }
+            return;
+        }
+
         if(!cursor.isSelecting()) {
             if(event.ctrlKey) {
                 var added = element.after({tag: element.getWlxmlTag() || 'div', klass: element.getWlxmlClass() || 'p'});
         if(!cursor.isSelecting()) {
             if(event.ctrlKey) {
                 var added = element.after({tag: element.getWlxmlTag() || 'div', klass: element.getWlxmlClass() || 'p'});