mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-03 04:31:46 +02:00
fix content loading in editor causes not to save
This commit is contained in:
@@ -149,18 +149,18 @@ function init_callback(_editor) {
|
||||
reactNativeEventHandler('focus', 'editor');
|
||||
});
|
||||
|
||||
editor.on('SetContent', function (event) {
|
||||
if (globalThis.isClearingNoteData) {
|
||||
globalThis.isClearingNoteData = false;
|
||||
return;
|
||||
}
|
||||
setTimeout(function () {
|
||||
editor.undoManager.transact(function () {});
|
||||
}, 1000);
|
||||
if (!event.paste) {
|
||||
reactNativeEventHandler('noteLoaded', true);
|
||||
}
|
||||
});
|
||||
// editor.on('SetContent', function (event) {
|
||||
// if (globalThis.isClearingNoteData) {
|
||||
// globalThis.isClearingNoteData = false;
|
||||
// return;
|
||||
// }
|
||||
// setTimeout(function () {
|
||||
// editor.undoManager.transact(function () {});
|
||||
// }, 1000);
|
||||
// if (!event.paste) {
|
||||
// reactNativeEventHandler('noteLoaded', true);
|
||||
// }
|
||||
// });
|
||||
|
||||
editor.on('NewBlock', function (e) {
|
||||
console.log('New Block');
|
||||
@@ -215,10 +215,13 @@ function init_callback(_editor) {
|
||||
block: 'nearest'
|
||||
});
|
||||
});
|
||||
editor.on('input', onChange);
|
||||
editor.on('keyup', onChange);
|
||||
editor.on('NodeChange', onChange);
|
||||
editor.on('compositionend', onChange);
|
||||
|
||||
editor.on('input ExecCommand ObjectResized Redo Undo', onChange);
|
||||
editor.on('keyup', e => {
|
||||
if (e.key !== 'Backspace') return;
|
||||
if (!editor.getHTML) return;
|
||||
onChange();
|
||||
});
|
||||
}
|
||||
|
||||
const plugins = [
|
||||
@@ -493,12 +496,20 @@ function delay(base = 0) {
|
||||
|
||||
let noteedited = false;
|
||||
const onChange = function (event) {
|
||||
console.log(event.type, event.selectionChange);
|
||||
if (event.type === 'nodechange' && !event.selectionChange) return;
|
||||
// console.log(event.type, event.selectionChange);
|
||||
// if (event.type === 'nodechange' && !event.selectionChange) return;
|
||||
|
||||
if (event.type && event.type.toLowerCase() === 'execcommand') {
|
||||
if (
|
||||
event.command.toLowerCase() === 'mcefocus' ||
|
||||
event.command.toLowerCase() === 'mcerepaint'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
isLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (prevCount === 0) {
|
||||
@@ -506,7 +517,8 @@ const onChange = function (event) {
|
||||
}
|
||||
|
||||
if (prevCount === 0 && event.type !== 'paste') return;
|
||||
if (event.type !== 'nodechange' && event.type !== 'compositionend') {
|
||||
console.log(event);
|
||||
if (event.type !== 'compositionend') {
|
||||
if (!noteedited) {
|
||||
noteedited = true;
|
||||
reactNativeEventHandler('noteedited');
|
||||
|
||||
@@ -150,14 +150,19 @@ function attachMessageListener() {
|
||||
|
||||
switch (type) {
|
||||
case 'inject':
|
||||
tinymce.activeEditor.setContent(value);
|
||||
tinymce.activeEditor.setHTML(value);
|
||||
break;
|
||||
case 'html':
|
||||
isLoading = true;
|
||||
globalThis.isClearingNoteData = false;
|
||||
tinymce.activeEditor.mode.set('readonly');
|
||||
if (!isInvalidValue(value)) {
|
||||
tinymce.activeEditor.setContent(value);
|
||||
tinymce.activeEditor.setHTML(value);
|
||||
reactNativeEventHandler('noteLoaded', true);
|
||||
globalThis.isClearingNoteData = false;
|
||||
setTimeout(function () {
|
||||
tinymce.activeEditor.undoManager.transact(function () {});
|
||||
}, 1000);
|
||||
} else {
|
||||
globalThis.isClearingNoteData = false;
|
||||
reactNativeEventHandler('noteLoaded', true);
|
||||
|
||||
@@ -118,7 +118,6 @@ export async function clearTimer(clear) {
|
||||
});
|
||||
}
|
||||
waitForContent = false;
|
||||
console.log("cleared timer & saving note",content.data);
|
||||
if (clear) {
|
||||
if (!noteEdited) return;
|
||||
if (
|
||||
@@ -449,22 +448,21 @@ export const _onMessage = async evt => {
|
||||
break;
|
||||
case 'tiny':
|
||||
if (message.sessionId !== sessionId) return;
|
||||
if (message.value === '<br>') return;
|
||||
if (message.value !== content.data) {
|
||||
if (prevNoteContent && message.value === prevNoteContent) {
|
||||
prevNoteContent = null;
|
||||
noteEdited = false;
|
||||
return;
|
||||
}
|
||||
|
||||
noteEdited = true;
|
||||
lastEditTime = Date.now();
|
||||
content = {
|
||||
type: message.type,
|
||||
data: message.value
|
||||
};
|
||||
onNoteChange();
|
||||
if (prevNoteContent && message.value === prevNoteContent) {
|
||||
prevNoteContent = null;
|
||||
noteEdited = false;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("tiny content recieved");
|
||||
|
||||
noteEdited = true;
|
||||
lastEditTime = Date.now();
|
||||
content = {
|
||||
type: message.type,
|
||||
data: message.value
|
||||
};
|
||||
onNoteChange();
|
||||
if (waitForContent) {
|
||||
eSendEvent('content_event');
|
||||
}
|
||||
@@ -607,7 +605,6 @@ export async function clearEditor(
|
||||
waitForContent = true;
|
||||
await clearTimer(true);
|
||||
}
|
||||
console.log(noteEdited, content.data);
|
||||
|
||||
disableSaving = true;
|
||||
db.fs.cancel(getNote()?.id);
|
||||
|
||||
@@ -8,7 +8,7 @@ document.getElementById("titleInput").value = '';
|
||||
autosize();
|
||||
window.prevContent = "";
|
||||
globalThis.isClearingNoteData = true;
|
||||
tinymce.activeEditor.setContent('');
|
||||
tinymce.activeEditor.setHTML('');
|
||||
tinymce.activeEditor.undoManager.clear();
|
||||
info = document.querySelector(infoBar);
|
||||
info.querySelector('#infosaved').innerText = "";
|
||||
@@ -90,7 +90,7 @@ const updateSavingState = value => `
|
||||
|
||||
export const clearEditor = `
|
||||
|
||||
tinymce.activeEditor.setContent("");
|
||||
tinymce.activeEditor.setHTML("");
|
||||
`;
|
||||
const clearTitle = `
|
||||
document.getElementById(titleInput).value = '';
|
||||
|
||||
Reference in New Issue
Block a user