8 var gridToggled = false;
12 register: function(name, command) {
13 this._cmds[name] = command;
16 run: function(name, params, canvas) {
17 return this._cmds[name](canvas, params);
21 commands.register('unwrap-node', function(canvas) {
22 var cursor = canvas.getCursor(),
23 selectionStart = cursor.getSelectionStart(),
24 selectionEnd = cursor.getSelectionEnd(),
25 parent1 = selectionStart.element.parent() || undefined,
26 parent2 = selectionEnd.element.parent() || undefined;
28 if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
29 canvas.list.extractItems({element1: parent1, element2: parent2});
30 } else if(!cursor.isSelecting()) {
31 var toUnwrap = cursor.getPosition().element,
32 parent = toUnwrap.unwrap();
33 canvas.setCurrentElement(parent);
37 commands.register('wrap-node', function(canvas) {
38 var cursor = canvas.getCursor(),
39 selectionStart = cursor.getSelectionStart(),
40 selectionEnd = cursor.getSelectionEnd(),
41 parent1 = selectionStart.element.parent() || undefined,
42 parent2 = selectionEnd.element.parent() || undefined;
44 if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
45 canvas.list.create({element1: parent1, element2: parent2});
49 commands.register('toggle-list', function(canvas, params) {
50 var cursor = canvas.getCursor(),
51 selectionStart = cursor.getSelectionStart(),
52 selectionEnd = cursor.getSelectionEnd(),
53 parent1 = selectionStart.element.parent() || undefined,
54 parent2 = selectionEnd.element.parent() || undefined;
57 canvas.list.create({element1: parent1, element2: parent2});
59 if(canvas.list.areItemsOfTheSameList({element1: parent1, element2: parent2})) {
60 canvas.list.extractItems({element1: parent1, element2: parent2, merge: false});
65 commands.register('toggle-grid', function(canvas, params) {
66 canvas.doc().dom().find('[wlxml-tag]').toggleClass('rng-common-hoveredNode', params.toggle);
67 gridToggled = params.toggle;
70 commands.register('newNodeRequested', function(canvas, params) {
71 var cursor = canvas.getCursor(),
72 selectionStart = cursor.getSelectionStart(),
73 selectionEnd = cursor.getSelectionEnd();
75 if(cursor.isSelecting() && cursor.isSelectingSiblings()) {
76 if(cursor.isSelectingWithinElement()) {
77 selectionStart.element.wrapWithNodeElement({tag: params.wlxmlTag, klass: params.wlxmlClass, start: selectionStart.offset, end: selectionEnd.offset});
80 var parent = selectionStart.element.parent();
83 _with: {tag: params.wlxmlTag, klass: params.wlxmlClass},
84 offsetStart: selectionStart.offset,
85 offsetEnd: selectionEnd.offset,
86 textNodeIdx: [parent.childIndex(selectionStart.element), parent.childIndex(selectionEnd.element)]
94 run: function(name, params, canvas) {
95 return commands.run(name, params, canvas);