+ }
+
+ var doc = s.canvas.wlxmlDocument;
+ doc.transaction(function() {
+
+ doc.deleteText({
+ from: {
+ node: s.startElement.wlxmlNode,
+ offset: s.startOffset
+ },
+ to: {
+ node: s.endElement.wlxmlNode,
+ offset: s.endOffset
+ }
+ });
+
+ }, {
+ success: function() {
+ if(goto) {
+ if(!doc.containsNode(goto.wlxmlNode)) {
+ goto = s.startElement;
+ caretTo = s.startOffset;
+ }
+ s.canvas.setCurrentElement(goto, {caretTo: caretTo});
+ }
+ }
+ });
+
+ }
+ },
+ { // enter on an empty list item - creates paragraph after list
+ 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'),
+ onlyChild = parent.contents().length === 1;
+ return s.type === 'caret' && e.key === KEYS.ENTER && s.element.isEmpty() && onlyChild &&
+ 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();
+ if(list.contents().length === 0) {
+ list.detach();
+ }
+ return p;
+ }, {
+ success: function(p) {
+ s.canvas.setCurrentElement(p);
+ }
+ });
+ }
+ },
+ { // enter - split node
+ applies: function(e, s) {
+ return s.type === 'caret' && e.key === KEYS.ENTER && !s.element.parent().isRootElement();
+ },
+ run: function(e, s) {
+ 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});
+ }, {
+ metadata: {
+ description: gettext('Splitting text'),
+ fragment: s.toDocumentFragment()
+ }
+ });
+
+ if(result.emptyText) {
+ goto = result.emptyText;
+ gotoOptions = {};