From: Jan Szejko Date: Fri, 23 Dec 2016 12:54:17 +0000 (+0100) Subject: pressing enter makes new paragraph after image/video X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/8f44492501cad481f4d4ddcd58f7e9b26e2a7721?ds=inline pressing enter makes new paragraph after image/video --- diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index bbdb0d4..bc7e2a7 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -179,7 +179,9 @@ $.extend(Canvas.prototype, Backbone.Events, { triggerKeyEvent: function(keyEvent, selection) { selection = selection || this.getSelection(); - if(selection && (selection.type === 'caret' || selection.type === 'textSelection') && selection.toDocumentFragment().isValid()) { + if(selection && ( + (selection.type === 'caret' || selection.type === 'textSelection') && selection.toDocumentFragment().isValid() + || selection.type == 'nodeSelection')) { keyboard.handleKeyEvent(keyEvent, selection); } }, diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index e43ea89..48fa0f9 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -413,6 +413,28 @@ var keyEventHandlers = [ s.canvas.setCurrentElement(utils.getElementForNode(goto), gotoOptions); } + }, + { + applies: function (e, s) { + return s.type === 'nodeSelection' && e.key === KEYS.ENTER && !s.element.isRootElement(); + }, + run: function (e, s) { + var parent = s.element.parent(), + children = parent.children(), + result, goto, gotoOptions; + e.preventDefault(); + + s.canvas.wlxmlDocument.transaction(function() { + result = s.element.wlxmlNode.insertNewNode(); + }, { + metadata: { + description: gettext('Splitting node'), + fragment: s.toDocumentFragment() + } + }); + + s.canvas.setCurrentElement(utils.getElementForNode(result), {caretTo: 'start'}); + } } ]; diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index bc41e00..7feb1a4 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -317,6 +317,13 @@ plugin.documentExtension.documentNode.transformations = { } }); return toret; + }, + insertNewNode: function () { + var node = this; + var newElement = this.document.createDocumentNode({tagName: 'div', attrs: {class: 'p'}}); + node.after(newElement); + newElement.append({text: ''}); + return newElement; } };