Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix editor is empty sometimes:

ammarahm-ed5c8f47e07693
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.js
index 2443c38d3..780371c95 100755
--- a/apps/mobile/html/Web.bundle/site/init.js
+++ b/apps/mobile/html/Web.bundle/site/init.js
@@ -231,7 +231,7 @@ function init_tiny(size) {
},
image_description: false,
image_caption: false,
- media_dimensions:false,
+ media_dimensions: false,
font_formats:
'Times New Roman=times new roman,times;' +
'Serif=serif;' +
@@ -278,7 +278,7 @@ function init_tiny(size) {
editor.ui.registry.addContextToolbar('iframecontrols', {
predicate: function (node) {
- return node.getAttribute("data-mce-object") === "iframe"
+ return node.getAttribute('data-mce-object') === 'iframe';
},
items: 'deletevideo',
position: 'node',
@@ -343,6 +343,10 @@ function init_tiny(size) {
});
editor.on('SetContent', function (event) {
+ if (globalThis.isClearingNoteData) {
+ globalThis.isClearingNoteData = false;
+ return;
+ }
if (!event.paste) {
reactNativeEventHandler('noteLoaded', true);
}
diff --git a/apps/mobile/html/Web.bundle/site/listeners.js b/apps/mobile/html/Web.bundle/site/listeners.js
index 7e728728b..70ca89121 100755
--- a/apps/mobile/html/Web.bundle/site/listeners.js
+++ b/apps/mobile/html/Web.bundle/site/listeners.js
@@ -126,6 +126,7 @@ function attachMessageListener() {
break;
case 'html':
isLoading = true;
+ globalThis.isClearingNoteData = false;
tinymce.activeEditor.mode.set('readonly');
tinymce.activeEditor.setContent(value);
setTimeout(function () {
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js
index ec0e0960f..90e1c4c74 100644
--- a/apps/mobile/src/views/Editor/EditorHeader.js
+++ b/apps/mobile/src/views/Editor/EditorHeader.js
@@ -106,9 +106,7 @@ const EditorHeader = () => {
}
useEditorStore.getState().setCurrentlyEditingNote(null);
await clearTimer(true);
- setTimeout(async () => {
- await clearEditor(false);
- }, 500);
+ await clearEditor(false,true,false);
Keyboard.removeListener('keyboardDidShow', tiny.onKeyboardShow);
}
};
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 68fdb584f..9f3ba6b9f 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -90,7 +90,6 @@ export async function clearTimer(clear) {
content.data?.trim().length > 0) ||
(title && title?.trim().length > 0 && id)
) {
- console.log('saving note now');
await saveNote(true);
}
}
@@ -192,13 +191,9 @@ export const loadNote = async item => {
}
if (item && item.type === 'new') {
- if (getNote()) {
- await clearEditor();
- }
+ await clearEditor(true, true, true);
clearNote();
-
noteEdited = false;
- id = null;
if (Platform.OS === 'android') {
await sleep(100);
textInput.current?.focus();
@@ -226,9 +221,8 @@ export const loadNote = async item => {
}
eSendEvent('loadingNote', item);
if (getNote()) {
- await clearEditor();
+ await clearEditor(true, false);
}
- clearNote();
noteEdited = false;
await setNote(item);
webviewInit = false;
@@ -240,9 +234,7 @@ export const loadNote = async item => {
eSendEvent('webviewreset');
}
}, 1);
- InteractionManager.runAfterInteractions(async () => {
- useEditorStore.getState().setCurrentlyEditingNote(item.id);
- }, 50);
+ useEditorStore.getState().setCurrentlyEditingNote(item.id);
}
};
@@ -265,6 +257,7 @@ const checkStatus = async noreset => {
webviewTimer = setTimeout(() => {
if (!webviewOK && !noreset) {
webviewInit = false;
+
EditorWebView = createRef();
eSendEvent('webviewreset');
resolve(false);
@@ -440,20 +433,36 @@ function onNoteChange() {
}, 500);
}
-export async function clearEditor(clear = true) {
+let cTimeout = null;
+export async function clearEditor(
+ clear = true,
+ reset = true,
+ immediate = false
+) {
clear && (await clearTimer(true));
- try {
- tiny.call(EditorWebView, tiny.reset, true);
- clearNote();
- editing.focusType = null;
- eSendEvent('historyEvent', {
- undo: 0,
- redo: 0
- });
- saveCounter = 0;
- useEditorStore.getState().setCurrentlyEditingNote(null);
- } catch (e) {
- console.log(e);
+ clearNote();
+ if (cTimeout) {
+ clearTimeout(cTimeout);
+ cTimeout = null;
+ }
+ let func = () => {
+ try {
+ reset && tiny.call(EditorWebView, tiny.reset, true);
+ editing.focusType = null;
+ eSendEvent('historyEvent', {
+ undo: 0,
+ redo: 0
+ });
+ saveCounter = 0;
+ useEditorStore.getState().setCurrentlyEditingNote(null);
+ } catch (e) {
+ console.log(e);
+ }
+ };
+ if (immediate) {
+ return func();
+ } else {
+ cTimeout = setTimeout(func, 500);
}
}
@@ -637,7 +646,6 @@ export const presentResolveConflictDialog = _note => {
};
export async function updateNoteInEditor() {
- console.log('trying to update.');
let _note = db.notes.note(id).data;
if (_note.conflicted) {
presentResolveConflictDialog(_note);
@@ -654,8 +662,6 @@ export async function updateNoteInEditor() {
post('title', title);
post('inject', content.data);
tiny.call(EditorWebView, tiny.notLoading);
-
- console.log('update content in editor complete');
}
const loadNoteInEditor = async (keepHistory = true) => {
@@ -664,11 +670,11 @@ const loadNoteInEditor = async (keepHistory = true) => {
if (note?.id) {
post('title', title);
intent = false;
-
if (!content || !content.data || content?.data?.length === 0) {
tiny.call(
EditorWebView,
`
+ globalThis.isClearingNoteData = false;
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: 'noteLoaded',
diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.js
index 0d44332a8..c09f44151 100644
--- a/apps/mobile/src/views/Editor/tiny/tiny.js
+++ b/apps/mobile/src/views/Editor/tiny/tiny.js
@@ -7,6 +7,7 @@ isLoading = true;
document.getElementById("titleInput").value = '';
autosize();
window.prevContent = "";
+globalThis.isClearingNoteData = true;
tinymce.activeEditor.setContent('');
tinymce.activeEditor.undoManager.clear();
info = document.querySelector(infoBar);
@@ -32,7 +33,6 @@ const keyboardStateChanged = `(function() {
const blur = `
document.activeElement.blur();
window.blur();
-
`;
const pre = `(function() {