Permalink
Browse files

Another fix for the WebKit backspace/delete bug.

  • Loading branch information...
spocke committed Feb 4, 2013
1 parent eb27b82 commit cd84a63d4addf27c60ef32dcbe1a49bbee30150a
Showing with 17 additions and 3 deletions.
  1. +17 −3 jscripts/tiny_mce/classes/util/Quirks.js
@@ -64,7 +64,7 @@ tinymce.util.Quirks = function(editor) {
*/
function cleanupStylesWhenDeleting() {
function removeMergedFormatSpans(isDelete) {
- var rng, blockElm, wrapperElm, bookmark, container, offset;
+ var rng, blockElm, wrapperElm, bookmark, container, offset, elm;
function isAtStartOrEndOfElm() {
if (container.nodeType == 3) {
@@ -79,6 +79,12 @@ tinymce.util.Quirks = function(editor) {
}
rng = selection.getRng();
+ var tmpRng = [rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset];
+
+ if (!rng.collapsed) {
+ isDelete = true;
+ }
+
container = rng[(isDelete ? 'start' : 'end') + 'Container'];
offset = rng[(isDelete ? 'start' : 'end') + 'Offset'];
@@ -90,7 +96,7 @@ tinymce.util.Quirks = function(editor) {
blockElm = dom.getNext(blockElm, dom.isBlock);
}
- if (blockElm && isAtStartOrEndOfElm()) {
+ if (blockElm && (isAtStartOrEndOfElm() || !rng.collapsed)) {
// Wrap children of block in a EM and let WebKit stick is
// runtime styles junk into that EM
wrapperElm = dom.create('em', {'id': '__mceDel'});
@@ -104,12 +110,20 @@ tinymce.util.Quirks = function(editor) {
}
// Do the backspace/delete action
+ rng = dom.createRng();
+ rng.setStart(tmpRng[0], tmpRng[1]);
+ rng.setEnd(tmpRng[2], tmpRng[3]);
+ selection.setRng(rng);
editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
// Remove temp wrapper element
if (wrapperElm) {
bookmark = selection.getBookmark();
- dom.remove(dom.get('__mceDel'), true);
+
+ while (elm = dom.get('__mceDel')) {
+ dom.remove(elm, true);
+ }
+
selection.moveToBookmark(bookmark);
}
}

1 comment on commit cd84a63

@tydesign

This comment has been minimized.

Show comment Hide comment
@tydesign

tydesign Mar 8, 2013

Hi there,

I'm fairly new to this. I came across this solution from reading this: http://core.trac.wordpress.org/ticket/23337 and it looks like you have a solution. But being new to coding (I know HTML/CSS only), how do I go about applying this fix?

Thank you for your patience and help.

Hi there,

I'm fairly new to this. I came across this solution from reading this: http://core.trac.wordpress.org/ticket/23337 and it looks like you have a solution. But being new to coding (I know HTML/CSS only), how do I go about applying this fix?

Thank you for your patience and help.

Please sign in to comment.