From 6cd9ff4975ba90953d3c6b3918e4c7a76af6d348 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 4 Aug 2014 16:41:25 +0200 Subject: [PATCH 1/1] editor: canvas fix --- .../modules/documentCanvas/canvas/keyboard.js | 2 +- src/editor/plugins/core/core.test.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index 3a90a90..6b32da0 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -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}); } }, diff --git a/src/editor/plugins/core/core.test.js b/src/editor/plugins/core/core.test.js index 67e3e7e..00fc421 100644 --- a/src/editor/plugins/core/core.test.js +++ b/src/editor/plugins/core/core.test.js @@ -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('
a
b
'), + 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); + }); + }); }); -- 2.20.1