mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix code mirror loading
This commit is contained in:
parent
8c5df6321f
commit
08af4a0465
@ -76,12 +76,12 @@ app.on('ready', () => {
|
|||||||
const dateNoteService = require('./src/services/date_notes');
|
const dateNoteService = require('./src/services/date_notes');
|
||||||
const dateUtils = require('./src/services/date_utils');
|
const dateUtils = require('./src/services/date_utils');
|
||||||
|
|
||||||
const parentNoteId = await dateNoteService.getDateNote(dateUtils.nowDate());
|
const parentNote = await dateNoteService.getDateNote(dateUtils.nowDate());
|
||||||
|
|
||||||
// window may be hidden / not in focus
|
// window may be hidden / not in focus
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
|
|
||||||
mainWindow.webContents.send('create-day-sub-note', parentNoteId);
|
mainWindow.webContents.send('create-day-sub-note', parentNote.noteId);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
@ -32,18 +32,19 @@ async function requireLibrary(library) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dynamicallyLoadedScripts = [];
|
// we save the promises in case of the same script being required concurrently multiple times
|
||||||
|
const loadedScriptPromises = {};
|
||||||
|
|
||||||
async function requireScript(url) {
|
async function requireScript(url) {
|
||||||
if (!dynamicallyLoadedScripts.includes(url)) {
|
if (!loadedScriptPromises[url]) {
|
||||||
dynamicallyLoadedScripts.push(url);
|
loadedScriptPromises[url] = $.ajax({
|
||||||
|
|
||||||
return await $.ajax({
|
|
||||||
url: url,
|
url: url,
|
||||||
dataType: "script",
|
dataType: "script",
|
||||||
cache: true
|
cache: true
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await loadedScriptPromises[url];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requireCss(url) {
|
async function requireCss(url) {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import utils from "./utils.js";
|
|
||||||
import libraryLoader from "./library_loader.js";
|
import libraryLoader from "./library_loader.js";
|
||||||
import bundleService from "./bundle.js";
|
import bundleService from "./bundle.js";
|
||||||
import infoService from "./info.js";
|
import infoService from "./info.js";
|
||||||
@ -11,15 +10,15 @@ const $noteDetailCode = $('#note-detail-code');
|
|||||||
const $executeScriptButton = $("#execute-script-button");
|
const $executeScriptButton = $("#execute-script-button");
|
||||||
|
|
||||||
async function show() {
|
async function show() {
|
||||||
if (!codeEditor) {
|
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||||
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
|
||||||
|
|
||||||
|
if (!codeEditor) {
|
||||||
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
||||||
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
||||||
|
|
||||||
CodeMirror.modeURL = 'libraries/codemirror/mode/%N/%N.js';
|
CodeMirror.modeURL = 'libraries/codemirror/mode/%N/%N.js';
|
||||||
|
|
||||||
codeEditor = CodeMirror($("#note-detail-code")[0], {
|
codeEditor = CodeMirror($noteDetailCode[0], {
|
||||||
value: "",
|
value: "",
|
||||||
viewportMargin: Infinity,
|
viewportMargin: Infinity,
|
||||||
indentUnit: 4,
|
indentUnit: 4,
|
||||||
@ -38,7 +37,7 @@ async function show() {
|
|||||||
|
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const currentNote = noteDetailService.getCurrentNote();
|
||||||
|
|
||||||
// this needs to happen after the element is shown, otherwise the editor won't be refresheds
|
// this needs to happen after the element is shown, otherwise the editor won't be refreshed
|
||||||
codeEditor.setValue(currentNote.content);
|
codeEditor.setValue(currentNote.content);
|
||||||
|
|
||||||
const info = CodeMirror.findModeByMIME(currentNote.mime);
|
const info = CodeMirror.findModeByMIME(currentNote.mime);
|
||||||
|
@ -57,7 +57,8 @@ function ScriptApi(startNote, currentNote) {
|
|||||||
formatDateISO: utils.formatDateISO,
|
formatDateISO: utils.formatDateISO,
|
||||||
parseDate: utils.parseDate,
|
parseDate: utils.parseDate,
|
||||||
showMessage: utils.showMessage,
|
showMessage: utils.showMessage,
|
||||||
showError: utils.showError
|
showError: utils.showError,
|
||||||
|
reloadTree: treeService.reload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user