+ if(e.which === KEYS.BACKSPACE) {
+ if(element.getText().length === 1) {
+ e.preventDefault();
+ element.setText('');
+ }
+ else if(element.isEmpty()) {
+ e.preventDefault();
+
+ var parent = element.parent(),
+ grandParent = parent ? parent.parent() : null,
+ goto;
+ if(parent.children().length === 1) {
+ if(grandParent && grandParent.children().length === 1) {
+ goto = grandParent.append({text: ''});
+ } else {
+ goto = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]', 'above', element.dom()[0]));
+ }
+ parent.detach();
+ } else {
+ goto = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]', 'above', element.dom()[0]));
+ element.detach();
+ }
+ canvas.setCurrentElement(goto, {caretTo: 'end'});
+ }
+ else if(position.offset === 0) {
+ // todo
+ }
+ }