direction = 'below';
caretTo = 'start';
cursorAtOperationEdge = s.isAtEnd();
- if(cursorAtOperationEdge) {
- element = cursorAtOperationEdge && s.canvas.getNearestTextElement(direction, s.element);
- }
+ element = cursorAtOperationEdge && s.canvas.getNearestTextElement(direction, s.element);
}
if(!cursorAtOperationEdge || !element) {
}
});
}
- },
+ },
+
+ {
+ applies: function(e,s) {
+ return s.type === 'caret' && s.element.getText().length === 1 && (e.key === KEYS.BACKSPACE || e.key === KEYS.DELETE);
+ },
+ run: function(e,s) {
+ e.preventDefault();
+ e.element.wlxmlNode.setText('');
+ s.canvas.setCurrentElement(s.element, {caretTo: 0});
+ }
+ },
{
applies: function(e, s) {
caretTo = 'end',
goto;
-
if(e.key === KEYS.DELETE) {
direction = 'below';
caretTo = 'start';
}
e.preventDefault();
- if(direction === 'above') {
+
+ if(s.startsAtBeginning && s.endsAtEnd && s.startElement.sameNode(s.endElement)) {
+ goto = s.startElement;
+ caretTo = s.startOffset;
+ } else if(direction === 'above') {
if(s.startsAtBeginning()) {
goto = s.canvas.getNearestTextElement('above', s.startElement);
caretTo = 'end';
}
}
- s.canvas.wlxmlDocument.deleteText({
- from: {
- node: s.startElement.wlxmlNode,
- offset: s.startOffset
- },
- to: {
- node: s.endElement.wlxmlNode,
- offset: s.endOffset
+ 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) {
+ s.canvas.setCurrentElement(goto, {caretTo: caretTo});
+ }
}
});
- if(goto) {
- s.canvas.setCurrentElement(goto, {caretTo: caretTo});
+
+ }
+ },
+ {
+ 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);
}
}
];