Fix: adding/clearing node widgets corrupted widgets on all children nodes
[fnpeditor.git] / modules / documentCanvas / commands.js
index bb86991..955ba48 100644 (file)
@@ -1,6 +1,6 @@
 define([
 define([
-
-], function() {
+'modules/documentCanvas/canvas/documentElement'
+], function(documentElement) {
     
 'use strict';
 
     
 'use strict';
 
@@ -48,7 +48,7 @@ commands.register('wrap-node', function(canvas) {
     }
 });
 
     }
 });
 
-commands.register('toggle-list', function(canvas, params) {
+commands.register('list', function(canvas, params) {
     var cursor = canvas.getCursor(),
         selectionStart = cursor.getSelectionStart(),
         selectionEnd = cursor.getSelectionEnd(),
     var cursor = canvas.getCursor(),
         selectionStart = cursor.getSelectionStart(),
         selectionEnd = cursor.getSelectionEnd(),
@@ -56,13 +56,13 @@ commands.register('toggle-list', function(canvas, params) {
         parent2 = selectionEnd.element.parent() || undefined;
 
     var selectionFocus = cursor.getSelectionFocus();
         parent2 = selectionEnd.element.parent() || undefined;
 
     var selectionFocus = cursor.getSelectionFocus();
-    if(params.toggle) {
-        canvas.list.create({element1: parent1, element2: parent2});
-    } else {
-        if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
-            canvas.list.extractItems({element1: parent1, element2: parent2, merge: false});
-        } 
+
+    if(selectionStart.element.isInsideList() || selectionEnd.element.isInsideList()) {
+        return;
     }
     }
+
+    canvas.list.create({element1: parent1, element2: parent2});
+
     canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset});
 });
 
     canvas.setCurrentElement(selectionFocus.element, {caretTo: selectionFocus.offset});
 });
 
@@ -107,17 +107,27 @@ commands.register('newNodeRequested', function(canvas, params) {
                 });
             }
         }
                 });
             }
         }
+    } else if(canvas.getCurrentNodeElement()) {
+        var el = canvas.getCurrentNodeElement().wrapWithNodeElement({tag: params.wlxmlTag, klass: params.wlxmlClass});
+        canvas.setCurrentElement(el);
     }
 
 
 });
 
 commands.register('footnote', function(canvas, params) {
     }
 
 
 });
 
 commands.register('footnote', function(canvas, params) {
-    var position = canvas.getCursor().getPosition();
+    var cursor = canvas.getCursor(),
+        position = cursor.getPosition(),
+        asideElement;
+        
 
 
-    var asideElement = position.element.divide({tag: 'aside', klass: 'footnote', offset: position.offset});
+    if(cursor.isSelectingWithinElement()) {
+        asideElement = position.element.wrapWithNodeElement({tag: 'aside', klass: 'footnote', start: cursor.getSelectionStart().offset, end: cursor.getSelectionEnd().offset});
+    } else {
+        asideElement = position.element.divide({tag: 'aside', klass: 'footnote', offset: position.offset});
+        asideElement.append({text: ''});
+    }
 
 
-    asideElement.append({text: ''});
     asideElement.toggle(true);
     canvas.setCurrentElement(asideElement);
 });
     asideElement.toggle(true);
     canvas.setCurrentElement(asideElement);
 });