X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/ff3715ae2dc79eda1edd45d462e5cc0c3e9803e4..ec10eee3168f37beedfb5dea757a4bdec2f2f36e:/src/editor/modules/documentCanvas/canvas/keyboard.js diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index b39a900..bd66c6e 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -504,6 +504,34 @@ var keyEventHandlers = [ }); } + }, + { + applies: function(e, s) { + return s.type === 'caret' && e.key === KEYS.ENTER && !s.element.parent().isRootElement(); + }, + run: function(e, s) { + var result, goto, gotoOptions; + void(e); + e.preventDefault(); + s.canvas.wlxmlDocument.transaction(function() { + result = s.element.wlxmlNode.breakContent({offset: s.offset}); + }, { + metadata: { + description: gettext('Splitting text'), + fragment: s.toDocumentFragment() + } + }); + + if(result.emptyText) { + goto = result.emptyText; + gotoOptions = {}; + } else { + goto = result.second; + gotoOptions = {caretTo: 'start'}; + } + + s.canvas.setCurrentElement(utils.getElementForNode(goto), gotoOptions); + } } ];