// delete the current line on backspace and delete, if it is empty, and move
// the caret into the adjacent element, rather than pulling content out
- if (e.which === this.keyCode.BACKSPACE || e.which === this.keyCode.DELETE) {
+ if (e.originalEvent.which === this.keyCode.BACKSPACE || e.originalEvent.which === this.keyCode.DELETE) {
if (selection.isCollapsed) {
- var range = selection.getRangeAt(0);
- var container = range.startContainer;
- if (container.nodeType === Node.TEXT_NODE) container = container.parentNode;
- if (container.nodeName === 'P' && container.childNodes.length === 1 && container.childNodes[0].textContent === '\u200B') {
- // simple comparison to check that at least one sibling is not null
- if (container.previousElementSibling !== container.nextElementSibling) {
- var caretEnd = null, caretStart = null;
-
- if (e.which === this.keyCode.BACKSPACE) {
- if (container.previousElementSibling === null) {
- caretStart = container.nextElementSibling;
+ var container = this.selection.block();
+ if (container.nodeName === 'P') {
+ // check if we're merging "adjacent" lists
+ if (this.list.combineAfterAndBefore(container)) {
+ e.originalEvent.preventDefault();
+ return;
+ }
+ else if (this.utils.isEmpty(container.innerHTML)) {
+ // simple comparison to check that at least one sibling is not null
+ if (container.previousElementSibling !== container.nextElementSibling) {
+ var caretEnd = null, caretStart = null;
+
+ if (e.originalEvent.which === this.keyCode.BACKSPACE) {
+ if (container.previousElementSibling === null) {
+ caretStart = container.nextElementSibling;
+ }
+ else {
+ caretEnd = container.previousElementSibling;
+ }
}
else {
- caretEnd = container.previousElementSibling;
+ if (container.nextElementSibling === null) {
+ caretEnd = container.previousElementSibling;
+ }
+ else {
+ caretStart = container.nextElementSibling;
+ }
}
- }
- else {
- if (container.nextElementSibling === null) {
- caretEnd = container.previousElementSibling;
+
+ elRemove(container);
+
+ if (caretStart === null) {
+ if (caretEnd.nodeName === 'OL' || caretEnd.nodeName === 'UL') {
+ caretEnd = caretEnd.lastElementChild;
+ }
+
+ this.caret.end(caretEnd);
}
else {
- caretStart = container.nextElementSibling;
+ if (caretStart.nodeName === 'OL' || caretStart.nodeName === 'UL') {
+ caretStart = caretStart.firstElementChild;
+ }
+
+ this.caret.start(caretStart);
}
+
+ e.originalEvent.preventDefault();
+ return;
}
-
- elRemove(container);
-
- if (caretStart === null) this.caret.end(caretEnd);
- else this.caret.start(caretStart);
-
- e.preventDefault();
- return;
}
}
+ else if (this.detect.isWebkit() && container.nodeName === 'LI' && e.which === this.keyCode.DELETE) {
+ // check if caret is at the end of the list item, and if there is an adjacent list item
+ var anchorNode = selection.anchorNode;
+ if (anchorNode.nodeType === Node.TEXT_NODE && anchorNode.textContent.length === selection.anchorOffset && anchorNode.parentNode.lastChild === anchorNode) {
+ var nextItem = container.nextElementSibling;
+ if (nextItem && nextItem.nodeName === 'LI') {
+ this.buffer.set();
+
+ this.selection.save();
+
+ while (nextItem.childNodes.length) {
+ container.appendChild(nextItem.childNodes[0]);
+ }
+ elRemove(nextItem);
+
+ this.selection.restore();
+
+ e.preventDefault();
+ return;
+ }
+ }
+ }
}
}