From: Aleksander Ɓukasz Date: Wed, 6 Aug 2014 08:58:21 +0000 (+0200) Subject: editor: canvas - do not break an empty paragraph on ENTER X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/612d7ff15c5ba8f014755af33b766f9db76f7df5?ds=sidebyside editor: canvas - do not break an empty paragraph on ENTER --- diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index c0dd361..a1965cd 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -241,6 +241,9 @@ $.extend(DocumentNodeElement.prototype, { // }) this.dom.css('display', what); this._container().css('display', what); + }, + children: function() { + return []; } }); diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index 7ae6b27..d8052ed 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -376,9 +376,16 @@ var keyEventHandlers = [ return s.type === 'caret' && e.key === KEYS.ENTER && !s.element.parent().isRootElement(); }, run: function(e, s) { - var result, goto, gotoOptions; + var parent = s.element.parent(), + children = parent.children(), + result, goto, gotoOptions; void(e); e.preventDefault(); + + if(children.length === 1 && s.element.isEmpty()) { + return; + } + s.canvas.wlxmlDocument.transaction(function() { result = s.element.wlxmlNode.breakContent({offset: s.offset}); }, { diff --git a/src/editor/plugins/core/core.test.js b/src/editor/plugins/core/core.test.js index f227b67..a33ae61 100644 --- a/src/editor/plugins/core/core.test.js +++ b/src/editor/plugins/core/core.test.js @@ -621,6 +621,17 @@ describe('Keyboard interactions', function() { expect(selection.offset).to.equal(0); }); + it('does nothing on an empty paragraph', function() { + var c = getCanvasFromXML('
a
'), + k = new Keyboard(c), + spy = sinon.spy(); + + k.withCaret('a|').press(K.BACKSPACE); + c.wlxmlDocument.on('change', spy); + k.press(K.ENTER); + expect(spy.callCount).to.equal(0); + }); + it('splits its parent box if inside a span', function() { var c = getCanvasFromXML('
this is a paragraph
'), k = new Keyboard(c);