better placement of the comment tutorial
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / keyboard.js
index 577c2fe..924a880 100644 (file)
@@ -238,26 +238,21 @@ var keyEventHandlers = [
             );
         },
         run: function(e,s) {
             );
         },
         run: function(e,s) {
-            var direction, caretTo, cursorAtOperationEdge, goto, element;
+            var goto, element;
 
             if(e.key === KEYS.BACKSPACE) {
 
             if(e.key === KEYS.BACKSPACE) {
-                direction = 'above';
-                caretTo = 'end';
-                cursorAtOperationEdge = s.isAtBeginning(); // always true?
                 element = s.element;
             }
             else {
                 element = s.element;
             }
             else {
-                direction = 'below';
-                caretTo = 'start';
-                cursorAtOperationEdge = s.isAtEnd(); // always true?
-                element = cursorAtOperationEdge && s.canvas.getNearestTextElement(direction, s.element);
+                element = s.canvas.getNearestTextElement('below', s.element);
             }
 
             }
 
-            if(!cursorAtOperationEdge || !element) {
+            e.preventDefault();
+
+            if(!element) {
                 return;
             }
 
                 return;
             }
 
-
             var parent = element.wlxmlNode.parent();
             if(element.wlxmlNode.getIndex() === 0 && parent.isContextRoot() && (!parent.is('item') || parent.getIndex() === 0)) {
                 // Don't even try to do anything at the edge of a context root, except for non-first items
             var parent = element.wlxmlNode.parent();
             if(element.wlxmlNode.getIndex() === 0 && parent.isContextRoot() && (!parent.is('item') || parent.getIndex() === 0)) {
                 // Don't even try to do anything at the edge of a context root, except for non-first items
@@ -265,8 +260,6 @@ var keyEventHandlers = [
                 return;
             }
 
                 return;
             }
 
-            e.preventDefault();
-
             s.canvas.wlxmlDocument.transaction(function() {
                 if(element.wlxmlNode.getIndex() === 0) {
                     goto = element.wlxmlNode.parent().moveUp();
             s.canvas.wlxmlDocument.transaction(function() {
                 if(element.wlxmlNode.getIndex() === 0) {
                     goto = element.wlxmlNode.parent().moveUp();
@@ -349,6 +342,10 @@ var keyEventHandlers = [
             }, {
                 success: function() {
                     if(goto) {
             }, {
                 success: function() {
                     if(goto) {
+                        if(!doc.containsNode(goto.wlxmlNode)) {
+                            goto = s.startElement;
+                            caretTo = s.startOffset;
+                        }
                         s.canvas.setCurrentElement(goto, {caretTo: caretTo});
                     }
                 }
                         s.canvas.setCurrentElement(goto, {caretTo: caretTo});
                     }
                 }
@@ -360,8 +357,10 @@ var keyEventHandlers = [
         applies: function(e, s) {
             var parent = s.element && s.element.wlxmlNode.parent(),
                 parentIsItem = parent && parent.is('item'),
         applies: function(e, s) {
             var parent = s.element && s.element.wlxmlNode.parent(),
                 parentIsItem = parent && parent.is('item'),
-                itemIsOnList = parent && parent.parent() && parent.parent().is('list');
-            return s.type === 'caret' && e.key === KEYS.ENTER && s.element.isEmpty() && parentIsItem && itemIsOnList;
+                itemIsOnList = parent && parent.parent() && parent.parent().is('list'),
+                onlyChild = parent.contents().length === 1;
+            return s.type === 'caret' && e.key === KEYS.ENTER && s.element.isEmpty() && onlyChild &&
+                parentIsItem && itemIsOnList;
         },
         run: function(e, s) {
             var item = s.element.wlxmlNode.parent(),
         },
         run: function(e, s) {
             var item = s.element.wlxmlNode.parent(),