editor: canvas fix
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 4 Aug 2014 14:41:25 +0000 (16:41 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:07:47 +0000 (16:07 +0200)
src/editor/modules/documentCanvas/canvas/keyboard.js
src/editor/plugins/core/core.test.js

index 3a90a90..6b32da0 100644 (file)
@@ -282,7 +282,7 @@ var keyEventHandlers = [
         },
         run: function(e,s) {
             e.preventDefault();
-            e.element.wlxmlNode.setText('');
+            s.element.wlxmlNode.setText('');
             s.canvas.setCurrentElement(s.element, {caretTo: 0});
         }
     },
index 67e3e7e..00fc421 100644 (file)
@@ -700,6 +700,26 @@ describe('Keyboard interactions', function() {
         });
     });
 
+    describe('Deleting text from a node', function() {
+        it('deletes last character with backspace', function() {
+            var c = getCanvasFromXML('<section><div class="p">a</div><div class="p">b</div></section>'),
+                k = new Keyboard(c);
+
+            k.withCaret('b|').press(K.BACKSPACE);
+
+            var rootContents = c.wlxmlDocument.root.contents();
+            expect(rootContents.length).to.equal(2);
+            expect(rootContents[0].is({tagName: 'div', klass: 'p'})).to.equal(true);
+            expect(rootContents[0].contents()[0].getText()).to.equal('a');
+            expect(rootContents[1].is({tagName: 'div', klass: 'p'})).to.equal(true);
+            expect(rootContents[1].contents()[0].getText()).to.equal('');
+
+            var selection = c.getSelection();
+            expect(selection.type).to.equal('caret');
+            expect(selection.element.sameNode(getTextElement('', c))).to.equal(true);
+            expect(selection.offset).to.equal(0);
+        });
+    });
 
 });