Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Worked on new workaround for delete/backspace bug on WebKit

  • Loading branch information...
commit baf5a5858b934aded5baf3d390f37a9535708d78 1 parent eb27b82
Johan Sörlin spocke authored
Showing with 43 additions and 35 deletions.
  1. +43 −35 jscripts/tiny_mce/classes/util/Quirks.js
78 jscripts/tiny_mce/classes/util/Quirks.js
View
@@ -63,54 +63,61 @@ tinymce.util.Quirks = function(editor) {
* This code is a bit of a hack and hopefully it will be fixed soon in WebKit.
*/
function cleanupStylesWhenDeleting() {
- function removeMergedFormatSpans(isDelete) {
- var rng, blockElm, wrapperElm, bookmark, container, offset;
+ function deleteContent(forward) {
+ var container, offset, node, rng, sibling;
- function isAtStartOrEndOfElm() {
- if (container.nodeType == 3) {
- if (isDelete && offset == container.length) {
- return true;
+ function hasNonEmptySibling(node) {
+ while (node = node[forward ? 'nextSibling' : 'previousSibling']) {
+ if (forward && node.nodeName == 'BR' && !node.nextSibling) {
+ return false;
}
- if (!isDelete && offset === 0) {
+ if (node.nodeType != 3 || node.data.length != 0) {
return true;
}
}
}
- rng = selection.getRng();
- container = rng[(isDelete ? 'start' : 'end') + 'Container'];
- offset = rng[(isDelete ? 'start' : 'end') + 'Offset'];
-
- if (container.nodeType == 3) {
- blockElm = dom.getParent(rng.startContainer, dom.isBlock);
+ function mergeSiblingBlocks(from, to) {
+ if (to.lastChild.nodeName == 'BR') {
+ dom.remove(to.lastChild);
+ }
- // On delete clone the root span of the next block element
- if (isDelete) {
- blockElm = dom.getNext(blockElm, dom.isBlock);
+ while (from.firstChild) {
+ to.appendChild(from.firstChild);
}
- if (blockElm && isAtStartOrEndOfElm()) {
- // Wrap children of block in a EM and let WebKit stick is
- // runtime styles junk into that EM
- wrapperElm = dom.create('em', {'id': '__mceDel'});
+ dom.remove(from);
+ }
- each(tinymce.grep(blockElm.childNodes), function(node) {
- wrapperElm.appendChild(node);
- });
+ rng = selection.getRng();
+ container = rng.startContainer;
+ offset = rng.startOffset;
- blockElm.appendChild(wrapperElm);
+ if (rng.collapsed && container.nodeType == 3 && offset == (forward ? container.length : 0)) {
+ node = container;
+ while (node && !dom.isBlock(node)) {
+ if (hasNonEmptySibling(node)) {
+ return false;
+ }
+
+ node = node.parentNode;
}
- }
- // Do the backspace/delete action
- editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
+ if (node) {
+ sibling = node[forward ? 'nextSibling' : 'previousSibling'];
+
+ if (dom.isBlock(sibling)) {
+ if (forward) {
+ mergeSiblingBlocks(sibling, node);
+ } else {
+ mergeSiblingBlocks(node, sibling);
+ }
+ }
- // Remove temp wrapper element
- if (wrapperElm) {
- bookmark = selection.getBookmark();
- dom.remove(dom.get('__mceDel'), true);
- selection.moveToBookmark(bookmark);
+ selection.setCursorLocation(container, offset);
+ return true;
+ }
}
}
@@ -119,12 +126,13 @@ tinymce.util.Quirks = function(editor) {
isDelete = e.keyCode == DELETE;
if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
- e.preventDefault();
- removeMergedFormatSpans(isDelete);
+ if (deleteContent(isDelete)) {
+ e.preventDefault();
+ }
}
});
- editor.addCommand('Delete', function() {removeMergedFormatSpans();});
+ editor.addCommand('Delete', function() {deleteContent(true);});
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.