Skip to content

Build your personal knowledge base with Trilium Notes

fix for protected note freezing because of double initialization of CKEditor

azivnerbc207d5e3045
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js
index 6a6839615c..58da247ddd 100644
--- a/src/public/javascripts/services/note_detail.js
+++ b/src/public/javascripts/services/note_detail.js
@@ -132,7 +132,7 @@ function newNoteCreated() {
}
async function handleProtectedSession() {
- await protectedSessionService.ensureProtectedSession(currentNote.isProtected, false);
+ const newSessionCreated = await protectedSessionService.ensureProtectedSession(currentNote.isProtected, false);
if (currentNote.isProtected) {
protectedSessionHolder.touchProtectedSession();
@@ -141,6 +141,8 @@ async function handleProtectedSession() {
// this might be important if we focused on protected note when not in protected note and we got a dialog
// to login, but we chose instead to come to another node - at that point the dialog is still visible and this will close it.
protectedSessionService.ensureDialogIsClosed();
+
+ return newSessionCreated;
}
async function loadNoteDetail(noteId) {
@@ -168,7 +170,11 @@ async function loadNoteDetail(noteId) {
$noteDetailComponents.hide();
- await handleProtectedSession();
+ const newSessionCreated = await handleProtectedSession();
+ if (newSessionCreated) {
+ // in such case we're reloading note anyway so no need to continue here.
+ return;
+ }
await getComponent(currentNote.type).show();
}
diff --git a/src/public/javascripts/services/note_detail_text.js b/src/public/javascripts/services/note_detail_text.js
index aff30b5fe5..943a51d27a 100644
--- a/src/public/javascripts/services/note_detail_text.js
+++ b/src/public/javascripts/services/note_detail_text.js
@@ -9,9 +9,13 @@ async function show() {
if (!textEditor) {
await libraryLoader.requireLibrary(libraryLoader.CKEDITOR);
- textEditor = await BalloonEditor.create($noteDetailText[0], {});
+ // textEditor might have been initialized during previous await so checking again
+ // looks like double initialization can freeze CKEditor pretty badly
+ if (!textEditor) {
+ textEditor = await BalloonEditor.create($noteDetailText[0], {});
- textEditor.model.document.on('change:data', noteDetailService.noteChanged);
+ textEditor.model.document.on('change:data', noteDetailService.noteChanged);
+ }
}
textEditor.setData(noteDetailService.getCurrentNote().content);
diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js
index 33f4aa9440..d77f6bf307 100644
--- a/src/public/javascripts/services/protected_session.js
+++ b/src/public/javascripts/services/protected_session.js
@@ -28,6 +28,7 @@ async function leaveProtectedSession() {
}
}
+/** returned promise resolves with true if new protected session was established, false if no action was necessary */
function ensureProtectedSession(requireProtectedSession, modal) {
const dfd = $.Deferred();
@@ -53,7 +54,7 @@ function ensureProtectedSession(requireProtectedSession, modal) {
});
}
else {
- dfd.resolve();
+ dfd.resolve(false);
}
return dfd.promise();
@@ -82,7 +83,7 @@ async function setupProtectedSession() {
$noteDetailWrapper.show();
- protectedSessionDeferred.resolve();
+ protectedSessionDeferred.resolve(true);
protectedSessionDeferred = null;
$protectedSessionOnButton.addClass('active');