From 81e36cf3c77bffbf2f352d7fbf3d7da611a5fa11 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 19 Mar 2021 16:21:25 -0400 Subject: [PATCH] Ace2Inner: Promisify `init()` --- src/static/js/ace.js | 3 +- src/static/js/ace2_inner.js | 57 ++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/static/js/ace.js b/src/static/js/ace.js index 95bd41f0e..e007dfdd4 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -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(); diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 8fef627b5..d35e15905 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -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(); };