X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6cd9ff4975ba90953d3c6b3918e4c7a76af6d348..ac50cae92710f684c801ad933b924de2bec2b460:/src/editor/modules/documentCanvas/canvas/keyboard.js?ds=sidebyside diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index 6b32da0..d8052ed 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -348,14 +348,44 @@ var keyEventHandlers = [ } }, + { + applies: function(e, s) { + var parent = s.element && s.element.wlxmlNode.parent(), + parentIsItem = parent && parent.is('item'), + itemIsOnList = parent && parent.parent() && parent.parent().is('list'); + return s.type === 'caret' && e.key === KEYS.ENTER && s.element.isEmpty() && parentIsItem && itemIsOnList; + }, + run: function(e, s) { + var item = s.element.wlxmlNode.parent(), + list = item.parent(); + e.preventDefault(); + s.canvas.wlxmlDocument.transaction(function() { + var p = list.after({tagName: 'div', attrs: {'class': 'p'}}); + p.append({text: ''}); + item.detach(); + return p; + }, { + success: function(p) { + s.canvas.setCurrentElement(p); + } + }); + } + }, { applies: function(e, s) { 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}); }, {