Skip to content

Commit

Permalink
fix: #284
Browse files Browse the repository at this point in the history
Bug where rows above a table cannot be deleted,
hotfix: iframe does not working in firefox
  • Loading branch information
JiHong88 committed Mar 27, 2020
1 parent 18382e8 commit f66484f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
32 changes: 25 additions & 7 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4093,7 +4093,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic
*/
_init: function (reload, _initHTML) {
this._ww = options.iframe ? context.element.wysiwygFrame.contentWindow : _w;
this._wd = options.iframe ? util.getIframeDocument(context.element.wysiwygFrame) : _d;
this._wd = _d;
if (options.iframe && options.height === 'auto') this._iframeAuto = this._wd.body;

this._allowHTMLComments = options._editorTagsWhitelist.indexOf('//') > -1;
Expand Down Expand Up @@ -4150,8 +4150,16 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic
this.history = _history(this, event._onChange_historyStack);

// Init, validate
this._initWysiwygArea(reload, _initHTML);
if (!options.iframe) this._initWysiwygArea(reload, _initHTML);
_w.setTimeout(function () {
// after iframe loaded
if (options.iframe) {
this._wd = context.element.wysiwygFrame.contentDocument;
context.element.wysiwyg = this._wd.body;
this._initWysiwygArea(reload, _initHTML);
if (options.height === 'auto') this._iframeAuto = this._wd.body;
}

this._checkComponents();
this._imagesInfoInit = false;
this._imagesInfoReset = false;
Expand Down Expand Up @@ -4810,16 +4818,16 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic
return false;
}

if (!formatEl.nextElementSibling && !formatEl.previousElementSibling && (util.isWysiwygDiv(formatEl.parentNode) && util.isFormatElement(formatEl) && !util.isListCell(formatEl) &&
(formatEl.childNodes.length <= 1 && (!formatEl.firstChild || util.onlyZeroWidthSpace(formatEl.firstChild.textContent))))) {
if (!formatEl.previousElementSibling && (util.isWysiwygDiv(formatEl.parentNode) && util.isFormatElement(formatEl) && !util.isListCell(formatEl) &&
(formatEl.childNodes.length <= 1 && (!formatEl.firstChild || util.onlyZeroWidthSpace(formatEl.textContent))))) {
e.preventDefault();
e.stopPropagation();
formatEl.innerHTML = '<br>';
const attrs = formatEl.attributes;
while (attrs[0]) {
formatEl.removeAttribute(attrs[0].name);
}
core.execCommand('formatBlock', false, 'P');
core.setRange(formatEl.firstChild, 1, formatEl.firstChild, 1);
return false;
}

Expand All @@ -4841,7 +4849,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic
}
}

util.removeItem(selectionNode.parentNode);
selectionNode.textContent = '';
util.removeItemAllParents(selectionNode, null, formatEl);
offset = typeof offset === 'number' ? offset : prev.nodeType === 3 ? prev.textContent.length : 1;
core.setRange(prev, offset, prev, offset);
break;
Expand Down Expand Up @@ -4961,9 +4970,17 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic

if (util.onlyZeroWidthSpace(formatEl)) {
util.removeItem(formatEl);
// table component
if (util.isTable(nextEl)) {
let cell = util.getChildElement(nextEl, util.isCell, false);
cell = cell.firstElementChild || cell;
core.setRange(cell, 0, cell, 0);
break;
}
}

if (util.hasClass(nextEl, 'se-component') || /^IMG$/i.test(nextEl.nodeName)) {
// resizing component
if (util.hasClass(nextEl, 'se-component') || /^(IMG|IFRAME)$/i.test(nextEl.nodeName)) {
e.stopPropagation();
if (util.hasClass(nextEl, 'se-image-container') || /^IMG$/i.test(nextEl.nodeName)) {
nextEl = /^IMG$/i.test(nextEl.nodeName) ? nextEl : nextEl.querySelector('img');
Expand All @@ -4972,6 +4989,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _ic
core.selectComponent(nextEl.querySelector('iframe'), 'video');
}
}

break;
}
}
Expand Down
29 changes: 20 additions & 9 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,27 @@ window.sun_destroy1 = function () {
}

window.sun_create1 = function () {
s1.destroy();
s1 = suneditor.create('editor', {
plugins: [align, plugins.link],
buttonList: [['align', 'link', 'bold', 'underline', 'italic', 'strike', 'removeFormat', 'codeView']],
width: '100%',
height: 'auto'
})
// s1.destroy();
// s1 = suneditor.create('editor', {
// plugins: [align, plugins.link],
// buttonList: [['align', 'link', 'bold', 'underline', 'italic', 'strike', 'removeFormat', 'codeView']],
// width: '100%',
// height: 'auto'
// })
}

s1.onKeyDown = function (e, core) {
const keyCode = e.keyCode
const ctrl = e.ctrlKey || e.metaKey || keyCode === 91 || keyCode === 92;
if (ctrl && keyCode === 187) {
e.preventDefault();
const anchor = core.util.getParentElement(core.getSelectionNode(), core.util.isAnchor)
if (anchor) {
window.open(anchor.href)
}
}
}


let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
// lang: lang.ko,
plugins: plugins,
Expand Down Expand Up @@ -273,7 +284,7 @@ let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
// ss.setContents('fsafsa')
ss.onload = function (core) {
console.log('onload', core);
core.focus();
// core.focus();
};
ss.onScroll = function (e) {
console.log('onScroll', e);
Expand Down

0 comments on commit f66484f

Please sign in to comment.