From: Aleksander Ɓukasz Date: Mon, 4 Aug 2014 14:41:25 +0000 (+0200) Subject: editor: canvas fix X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/6cd9ff4975ba90953d3c6b3918e4c7a76af6d348?ds=sidebyside;hp=-c editor: canvas fix --- 6cd9ff4975ba90953d3c6b3918e4c7a76af6d348 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); + }); + }); });