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);
}
},
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'});
+ }
}
];
}
});
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;
}
};