Hello,
I managed to find & fix where the problems came from.
First, the Api.prototype["pluginMethod_PasteHtml"]
return callback is called right away when the function is finished, and not when the execution is finished (loading the images in this case).
So, I used the same functionality as ReplaceTextSmart
:
let guid = window.g_asc_plugins ? window.g_asc_plugins.setPluginMethodReturnAsync() : null;
....
if (guid)
window.g_asc_plugins.onPluginMethodReturn(guid, true);
The second problem came from the function this.asc_PasteData, this function has a callback that has not been used, so when the images are loaded the callback has been called already.
so here is my fix, let me know what you think:
Api.prototype["pluginMethod_PasteHtml"] = function(htmlText) {
if (!AscCommon.g_clipboardBase)
return null;
if (this.isViewMode)
return null;
var _elem = document.getElementById("pmpastehtml");
if (_elem)
return;
let guid = window.g_asc_plugins ? window.g_asc_plugins.setPluginMethodReturnAsync() : null;
_elem = document.createElement("div");
_elem.id = "pmpastehtml";
if (this.editorId == AscCommon.c_oEditorId.Word || this.editorId == AscCommon.c_oEditorId.Presentation) {
var textPr = this.get_TextProps();
if (textPr) {
if (undefined !== textPr.TextPr.FontSize)
_elem.style.fontSize = textPr.TextPr.FontSize + "pt";
_elem.style.fontWeight = (true === textPr.TextPr.Bold) ? "bold" : "normal";
_elem.style.fontStyle = (true === textPr.TextPr.Italic) ? "italic" : "normal";
var _color = textPr.TextPr.Color;
if (_color)
_elem.style.color = "rgb(" + _color.r + "," + _color.g + "," + _color.b + ")";
else
_elem.style.color = "rgb(0,0,0)";
}
} else if (this.editorId == AscCommon.c_oEditorId.Spreadsheet) {
var props = this.asc_getCellInfo();
if (props && props.font) {
if (undefined != props.font.size)
_elem.style.fontSize = props.font.size + "pt";
_elem.style.fontWeight = (true === props.font.bold) ? "bold" : "normal";
_elem.style.fontStyle = (true === props.font.italic) ? "italic" : "normal";
}
}
_elem.innerHTML = htmlText;
document.body.appendChild(_elem);
this.asc_setVisiblePasteButton(false);
this.incrementCounterLongAction();
var b_old_save_format = AscCommon.g_clipboardBase.bSaveFormat;
AscCommon.g_clipboardBase.bSaveFormat = false;
var self = this;
this.asc_PasteData(AscCommon.c_oAscClipboardDataFormat.HtmlElement, _elem, undefined, undefined, undefined,
function() {
self.decrementCounterLongAction();
if (true) {
var fCallback = function() {
document.body.removeChild(_elem);
_elem = null;
AscCommon.g_clipboardBase.bSaveFormat = b_old_save_format;
};
if (self.checkLongActionCallback(fCallback, null)) {
fCallback();
}
} else {
document.body.removeChild(_elem);
_elem = null;
AscCommon.g_clipboardBase.bSaveFormat = b_old_save_format;
}
if (guid)
window.g_asc_plugins.onPluginMethodReturn(guid, true);
}
);
};
best,