pad_editor: Promisify `init()`

pull/4966/head
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:
padimpexp.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);
padconnectionstatus.init();
padmodals.init(this);

View File

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