integration wip: highlight/dim/select node via breadcrumbs
[fnpeditor.git] / src / editor / modules / documentCanvas / commands.js
index 69dd305..ac56a31 100644 (file)
@@ -27,27 +27,31 @@ commands.register('unwrap-node', function(canvas) {
         parent2 = selectionEnd.element.parent() || undefined;
 
     if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
         parent2 = selectionEnd.element.parent() || undefined;
 
     if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
-        var selectionAnchor = cursor.getSelectionAnchor();
-        canvas.list.extractItems({element1: parent1, element2: parent2});
-        canvas.setCurrentElement(selectionAnchor.element, {caretTo: selectionAnchor.offset});
+        return;
+        // TODO
+        // var selectionAnchor = cursor.getSelectionAnchor();
+        // canvas.list.extractItems({element1: parent1, element2: parent2});
+        // canvas.setCurrentElement(selectionAnchor.element, {caretTo: selectionAnchor.offset});
     } else if(!cursor.isSelecting()) {
     } else if(!cursor.isSelecting()) {
-        var toUnwrap = cursor.getPosition().element,
-            parent = toUnwrap.unwrap();
-        canvas.setCurrentElement(parent);
+        var nodeToUnwrap = cursor.getPosition().element.data('wlxmlNode'),
+            parentNode = nodeToUnwrap.unwrap();
+        if(parentNode) {
+            canvas.setCurrentElement(utils.findCanvasElement(parentNode));
+        }
     }
 });
 
     }
 });
 
-commands.register('wrap-node', function(canvas) {
-    var cursor = canvas.getCursor(),
-        selectionStart = cursor.getSelectionStart(),
-        selectionEnd = cursor.getSelectionEnd(),
-        parent1 = selectionStart.element.parent() || undefined,
-        parent2 = selectionEnd.element.parent() || undefined;
+// commands.register('wrap-node', function(canvas) {
+//     var cursor = canvas.getCursor(),
+//         selectionStart = cursor.getSelectionStart(),
+//         selectionEnd = cursor.getSelectionEnd(),
+//         parent1 = selectionStart.element.parent() || undefined,
+//         parent2 = selectionEnd.element.parent() || undefined;
 
 
-    if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
-        canvas.list.create({element1: parent1, element2: parent2});
-    }
-});
+//     if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
+//         canvas.list.create({element1: parent1, element2: parent2});
+//     }
+// });
 
 commands.register('list', function(canvas, params) {
     var cursor = canvas.getCursor(),
 
 commands.register('list', function(canvas, params) {
     var cursor = canvas.getCursor(),
@@ -147,7 +151,7 @@ commands.register('take-away-node', function(canvas) {
         return;
 
 
         return;
 
 
-    var range = nodeElement.unwrapContents();
+    var range = nodeElement.data('wlxmlNode').unwrapContent();
 
     if(element) {
         var elementIsFirstChild = nodeElement.childIndex(element);
 
     if(element) {
         var elementIsFirstChild = nodeElement.childIndex(element);
@@ -155,13 +159,13 @@ commands.register('take-away-node', function(canvas) {
             canvas.setCurrentElement(element, {caretTo: position.offset});
         } else {
             if(elementIsFirstChild) {
             canvas.setCurrentElement(element, {caretTo: position.offset});
         } else {
             if(elementIsFirstChild) {
-                canvas.setCurrentElement(range.element1, {caretTo: 'end'});
+                canvas.setCurrentElement(findCanvasElement(range.element1), {caretTo: 'end'});
             } else {
             } else {
-                canvas.setCurrentElement(range.element2, {caretTo: 'end'});
+                canvas.setCurrentElement(findCanvasElement(range.element2), {caretTo: 'end'});
             }
         }
     } else {
             }
         }
     } else {
-        canvas.setCurrentElement(range.element1, {caretTo: 'start'});
+        canvas.setCurrentElement(findCanvasElement(range.element1), {caretTo: 'start'});
     }
 
 });
     }
 
 });