Ace2Inner: Promisify init()

This commit is contained in:
Richard Hansen 2021-03-19 16:21:25 -04:00 committed by John McLear
parent 742a7cd430
commit 81e36cf3c7
2 changed files with 28 additions and 32 deletions

View file

@ -307,8 +307,7 @@ const Ace2Editor = function () {
await new Promise((resolve, reject) => innerWindow.plugins.ensure(
(err) => err != null ? reject(err) : resolve()));
debugLog('Ace2Editor.init() waiting for Ace2Inner.init()');
await new Promise((resolve, reject) => innerWindow.Ace2Inner.init(
info, (err) => err != null ? reject(err) : resolve()));
await innerWindow.Ace2Inner.init(info);
debugLog('Ace2Editor.init() Ace2Inner.init() returned');
loaded = true;
doActionsPendingInit();

View file

@ -3895,44 +3895,41 @@ function Ace2Inner(editorInfo) {
editorInfo.ace_performDocumentApplyAttributesToRange =
(...args) => documentAttributeManager.setAttributesOnRange(...args);
this.init = (cb) => {
$(document).ready(() => {
doc = document; // defined as a var in scope outside
inCallStack('setup', () => {
const body = doc.getElementById('innerdocbody');
root = body; // defined as a var in scope outside
if (browser.firefox) $(root).addClass('mozilla');
if (browser.safari) $(root).addClass('safari');
root.classList.toggle('authorColors', true);
root.classList.toggle('doesWrap', doesWrap);
this.init = async () => {
await $.ready;
doc = document; // defined as a var in scope outside
inCallStack('setup', () => {
const body = doc.getElementById('innerdocbody');
root = body; // defined as a var in scope outside
if (browser.firefox) $(root).addClass('mozilla');
if (browser.safari) $(root).addClass('safari');
root.classList.toggle('authorColors', true);
root.classList.toggle('doesWrap', doesWrap);
initDynamicCSS();
initDynamicCSS();
enforceEditability();
enforceEditability();
// set up dom and rep
while (root.firstChild) root.removeChild(root.firstChild);
const oneEntry = createDomLineEntry('');
doRepLineSplice(0, rep.lines.length(), [oneEntry]);
insertDomLines(null, [oneEntry.domInfo]);
rep.alines = Changeset.splitAttributionLines(
Changeset.makeAttribution('\n'), '\n');
// set up dom and rep
while (root.firstChild) root.removeChild(root.firstChild);
const oneEntry = createDomLineEntry('');
doRepLineSplice(0, rep.lines.length(), [oneEntry]);
insertDomLines(null, [oneEntry.domInfo]);
rep.alines = Changeset.splitAttributionLines(
Changeset.makeAttribution('\n'), '\n');
bindTheEventHandlers();
});
bindTheEventHandlers();
});
hooks.callAll('aceInitialized', {
editorInfo,
rep,
documentAttributeManager,
});
scheduler.setTimeout(cb, 0);
hooks.callAll('aceInitialized', {
editorInfo,
rep,
documentAttributeManager,
});
};
}
exports.init = (editorInfo, cb) => {
exports.init = async (editorInfo) => {
const editor = new Ace2Inner(editorInfo);
editor.init(cb);
await editor.init();
};