diff --git a/src/polyfills.js b/src/polyfills.js index 4080e5e..afc1c7c 100644 --- a/src/polyfills.js +++ b/src/polyfills.js @@ -478,6 +478,31 @@ wysihtml5.polyfills = function(win, doc) { } else { F(); } + + // CustomEvent for ie9 and up + function nativeCustomEventSupported() { + try { + var p = new CustomEvent('cat', {detail: {foo: 'bar'}}); + return 'cat' === p.type && 'bar' === p.detail.foo; + } catch (e) {} + return false; + } + var customEventSupported = nativeCustomEventSupported(); + + // Polyfills CustomEvent object for IE9 and up + (function() { + if (!customEventSupported && "CustomEvent" in window) { + function CustomEvent(event, params) { + params = params || {bubbles: false, cancelable: false, detail: undefined}; + var evt = doc.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt; + } + CustomEvent.prototype = win.Event.prototype; + win.CustomEvent = CustomEvent; + customEventSupported = true; + } + })(); }; wysihtml5.polyfills(window, document); diff --git a/src/selection/selection.js b/src/selection/selection.js index d81cf8e..ae759cb 100644 --- a/src/selection/selection.js +++ b/src/selection/selection.js @@ -580,6 +580,11 @@ startOffset = (sel.isBackwards()) ? sel.focusOffset : sel.anchorOffset, rng = this.createRange(), endNode, inTmpCaret; + // If start is textnode and all is whitespace before caret. Set start offset to 0 + if (startNode && startNode.nodeType === 3 && (/^\s*$/).test(startNode.data.slice(0, startOffset))) { + startOffset = 0; + } + // Escape temproray helper nodes if selection in them inTmpCaret = wysihtml5.dom.getParentElement(startNode, { query: '._wysihtml5-temp-caret-fix' }, 1); if (inTmpCaret) { diff --git a/src/views/composer.observe.js b/src/views/composer.observe.js index 224b087..3d280f3 100644 --- a/src/views/composer.observe.js +++ b/src/views/composer.observe.js @@ -59,7 +59,7 @@ return true; } try { - var ev = new CustomEvent("wysihtml5:uneditable:delete"); + var ev = new CustomEvent("wysihtml5:uneditable:delete", {bubbles: true, cancelable: false}); before.node.dispatchEvent(ev); } catch (err) {} before.node.parentNode.removeChild(before.node); @@ -154,18 +154,19 @@ element = composer.element; if (selection.isCollapsed()) { - if (fixDeleteInTheBeginningOfLi(composer)) { + if (handleUneditableDeletion(composer)) { event.preventDefault(); return; - } else if (fixDeleteInTheBeginningOfBlock(composer)) { + } + if (fixDeleteInTheBeginningOfLi(composer)) { event.preventDefault(); return; } - if (fixLastBrDeletionInTable(composer)) { + if (fixDeleteInTheBeginningOfBlock(composer)) { event.preventDefault(); return; } - if (handleUneditableDeletion(composer)) { + if (fixLastBrDeletionInTable(composer)) { event.preventDefault(); return; }