pad_editor: Promisify init()

This commit is contained in:
Richard Hansen 2021-03-19 16:35:36 -04:00 committed by John McLear
parent 81e36cf3c7
commit e2bfe2fd10
2 changed files with 11 additions and 21 deletions

View file

@ -501,7 +501,7 @@ const pad = {
// order of inits is important here: // order of inits is important here:
padimpexp.init(this); padimpexp.init(this);
padsavedrevs.init(this); padsavedrevs.init(this);
padeditor.init(postAceInit, pad.padOptions.view || {}, this); padeditor.init(pad.padOptions.view || {}, this).then(postAceInit);
paduserlist.init(pad.myUserInfo, this); paduserlist.init(pad.myUserInfo, this);
padconnectionstatus.init(); padconnectionstatus.init();
padmodals.init(this); padmodals.init(this);

View file

@ -34,30 +34,20 @@ const padeditor = (() => {
ace: null, ace: null,
// this is accessed directly from other files // this is accessed directly from other files
viewZoom: 100, viewZoom: 100,
init: (readyFunc, initialViewOptions, _pad) => { init: async (initialViewOptions, _pad) => {
Ace2Editor = require('./ace').Ace2Editor; Ace2Editor = require('./ace').Ace2Editor;
pad = _pad; pad = _pad;
settings = pad.settings; settings = pad.settings;
self.ace = new Ace2Editor();
const aceReady = () => { await self.ace.init('editorcontainer', '');
$('#editorloadingbox').hide(); $('#editorloadingbox').hide();
if (readyFunc) {
readyFunc();
// Listen for clicks on sidediv items // Listen for clicks on sidediv items
const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody'); const $outerdoc = $('iframe[name="ace_outer"]').contents().find('#outerdocbody');
$outerdoc.find('#sidedivinner').on('click', 'div', function () { $outerdoc.find('#sidedivinner').on('click', 'div', function () {
const targetLineNumber = $(this).index() + 1; const targetLineNumber = $(this).index() + 1;
window.location.hash = `L${targetLineNumber}`; window.location.hash = `L${targetLineNumber}`;
}); });
exports.focusOnLine(self.ace); exports.focusOnLine(self.ace);
}
};
self.ace = new Ace2Editor();
self.ace.init('editorcontainer', '').then(
() => aceReady(), (err) => { throw err || new Error(err); });
self.ace.setProperty('wraps', true); self.ace.setProperty('wraps', true);
if (pad.getIsDebugEnabled()) { if (pad.getIsDebugEnabled()) {
self.ace.setProperty('dmesg', pad.dmesg); self.ace.setProperty('dmesg', pad.dmesg);