A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
change editor working logic
ammarahm-ed63f110413a3b
diff --git a/apps/mobile/html/Web.bundle/site/init.js b/apps/mobile/html/Web.bundle/site/init.jsindex 75cb80f33..77232b994 100755--- a/apps/mobile/html/Web.bundle/site/init.js+++ b/apps/mobile/html/Web.bundle/site/init.js@@ -603,7 +603,9 @@ const onChange = function (event) {if (event.type && event.type.toLowerCase() === 'execcommand') {if (event.command.toLowerCase() === 'mcefocus' ||- event.command.toLowerCase() === 'mcerepaint'+ event.command.toLowerCase() === 'mcerepaint' ||+ event.command.toLowerCase() === 'mcedirectionrtl' ||+ event.command.toLowerCase() === 'mcedirectionltr') {return;}diff --git a/apps/mobile/src/components/Header/index.js b/apps/mobile/src/components/Header/index.jsindex e170ce892..12a11260d 100644--- a/apps/mobile/src/components/Header/index.js+++ b/apps/mobile/src/components/Header/index.js@@ -44,7 +44,7 @@ export const Header = React.memo(overflow: 'hidden',borderBottomWidth: 1,borderBottomColor: hide ? 'transparent' : colors.nav,- justifyContent: 'space-between'+ justifyContent: 'space-between',}]}><View style={styles.leftBtnContainer}>diff --git a/apps/mobile/src/navigation/RootView.js b/apps/mobile/src/navigation/RootView.jsindex 5129b9f9b..25bb5d05a 100644--- a/apps/mobile/src/navigation/RootView.js+++ b/apps/mobile/src/navigation/RootView.js@@ -51,7 +51,10 @@ const onChangeTab = async obj => {eSendEvent(eOnLoadNote, {type: 'new'});editing.currentlyEditing = true;}- sleep(1000).then(() => {+ if (getNote()) {+ await checkStatus();+ }+ sleep(1000).then(() => {updateStatusBarColor();});} else {diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.tsindex f7412dcbd..27ac4f998 100644--- a/apps/mobile/src/provider/stores.ts+++ b/apps/mobile/src/provider/stores.ts@@ -290,6 +290,7 @@ export const useEditorStore = create<EditorStore>((set, get) => ({sessionId: null,setSessionId: sessionId => {console.log(sessionId, 'session id');+ tiny.call(EditorWebView,`sessionId="${sessionId}";`);set({sessionId});},searchReplace: false,diff --git a/apps/mobile/src/utils/useAppEvents.js b/apps/mobile/src/utils/useAppEvents.jsindex 7b005ee79..f092a636f 100644--- a/apps/mobile/src/utils/useAppEvents.js+++ b/apps/mobile/src/utils/useAppEvents.js@@ -557,6 +557,7 @@ export const useAppEvents = () => {eSendEvent(refreshNotesPage);}if (notesAddedFromIntent || shareExtensionOpened) {+ eSendEvent("loadingNote",getNote());eSendEvent('webviewreset', true);MMKV.removeItem('shareExtensionOpened');}diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex f2907d8c3..5a80a32af 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -1,5 +1,5 @@-import { EV, EVENTS } from 'notes-core/common';-import React, { useEffect, useRef } from 'react';+import {EV, EVENTS} from 'notes-core/common';+import React, {useEffect, useRef} from 'react';import {BackHandler,InteractionManager,@@ -8,17 +8,17 @@ import {Vibration,View} from 'react-native';-import { useSafeAreaInsets } from 'react-native-safe-area-context';-import { notesnook } from '../../../e2e/test.ids';-import { ActionIcon } from '../../components/ActionIcon';-import { Properties } from '../../components/Properties';-import { useTracked } from '../../provider';+import {useSafeAreaInsets} from 'react-native-safe-area-context';+import {notesnook} from '../../../e2e/test.ids';+import {ActionIcon} from '../../components/ActionIcon';+import {Properties} from '../../components/Properties';+import {useTracked} from '../../provider';import {useEditorStore,useSettingStore,useUserStore} from '../../provider/stores';-import { DDS } from '../../services/DeviceDetection';+import {DDS} from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,@@ -26,8 +26,8 @@ import {ToastEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';-import { editing, SUBSCRIPTION_STATUS } from '../../utils';-import { db } from '../../utils/database';+import {editing, SUBSCRIPTION_STATUS} from '../../utils';+import {db} from '../../utils/database';import {eClearEditor,eCloseFullscreenEditor,@@ -37,21 +37,22 @@ import {eOpenPremiumDialog,eOpenPublishNoteDialog} from '../../utils/Events';-import { tabBarRef } from '../../utils/Refs';-import { EditorTitle } from './EditorTitle';+import {tabBarRef} from '../../utils/Refs';+import {EditorTitle} from './EditorTitle';import {clearEditor,- clearTimer, getNote,+ clearTimer,+ getNote,loadNote,setColors,startClosingSession} from './Functions';-import { ProgressCircle } from './ProgressCircle';-import tiny, { safeKeyboardDismiss } from './tiny/tiny';-import { endSearch } from './tiny/toolbar/commands';-import { toolbarRef } from './tiny/toolbar/constants';+import {ProgressCircle} from './ProgressCircle';+import tiny, {safeKeyboardDismiss} from './tiny/tiny';+import {endSearch} from './tiny/toolbar/commands';+import {toolbarRef} from './tiny/toolbar/constants';import picker from './tiny/toolbar/picker';-import { useEditorTags } from './useEditorTags';+import {useEditorTags} from './useEditorTags';const EditorHeader = () => {const [state] = useTracked();@@ -114,7 +115,7 @@ const EditorHeader = () => {useEditorStore.getState().setCurrentlyEditingNote(null);}, 1);keyboardListener.current?.remove();- await clearEditor(true, true, true);+ await clearEditor();}closing.current = false;}, 1);@@ -216,7 +217,6 @@ const EditorHeader = () => {}return () => {- clearTimer();if (handleBack.current) {handleBack.current.remove();handleBack.current = null;@@ -278,143 +278,137 @@ const EditorHeader = () => {<Viewstyle={{width: '100%',- position: 'relative',backgroundColor: colors.bg,- right: 0,marginTop: Platform.OS === 'ios' ? 0 : insets.top,- zIndex: 10+ flexDirection: 'row',+ paddingHorizontal: 12,+ height: 50,+ justifyContent:'space-between'+}}><Viewstyle={{flexDirection: 'row',- paddingHorizontal: 12,- width: '100%',- height: 50,- justifyContent: 'space-between',- alignItems: 'center'+ alignItems: 'center',+ flexGrow: 1,+ flexShrink: 1}}>- <View- style={{- flexDirection: 'row',- alignItems: 'center'- }}>- {deviceMode !== 'mobile' && !fullscreen ? null : (- <ActionIcon- onLongPress={async () => {- await _onBackPress();- Navigation.popToTop();- }}- top={50}- left={12}- testID={notesnook.editor.back}- name="arrow-left"- color={colors.pri}- onPress={_onBackPress}- bottom={5}- customStyle={{- marginLeft: -5- }}- />- )}- {fullscreen ? <View style={{width: 20}} /> : null}- {deviceMode !== 'mobile' ? <EditorTitle /> : null}- </View>+ {deviceMode !== 'mobile' && !fullscreen ? null : (+ <ActionIcon+ onLongPress={async () => {+ await _onBackPress();+ Navigation.popToTop();+ }}+ top={50}+ left={12}+ testID={notesnook.editor.back}+ name="arrow-left"+ color={colors.pri}+ onPress={_onBackPress}+ bottom={5}+ customStyle={{+ marginLeft: -5+ }}+ />+ )}+ {fullscreen ? <View style={{width: 20}} /> : null}+ {deviceMode !== 'mobile' ? <EditorTitle /> : null}+ </View>- <View- style={{- flexDirection: 'row'- }}>- <>- {!user ||- user?.subscription.type === SUBSCRIPTION_STATUS.BASIC ||- user?.subscription.type === SUBSCRIPTION_STATUS.TRIAL ? (- <ActionIcon- name="crown"- color={colors.yellow}- customStyle={{- marginLeft: 5- }}- top={50}- onPress={async () => {- if (editing.isFocused) {- safeKeyboardDismiss();- editing.isFocused = true;- }- eSendEvent(eOpenPremiumDialog);- }}- />- ) : null}+ <View+ style={{+ flexDirection: 'row',+ }}>+ <>+ {!user ||+ user?.subscription.type === SUBSCRIPTION_STATUS.BASIC ||+ user?.subscription.type === SUBSCRIPTION_STATUS.TRIAL ? (<ActionIcon- name="magnify"- color={searchReplace ? colors.accent : colors.pri}+ name="crown"+ color={colors.yellow}customStyle={{marginLeft: 5}}- type={searchReplace ? 'grayBg' : 'transparent'}top={50}- buttom={10}- onLongPress={() => {- if (searchReplace) {- endSearch();- Vibration.vibrate(5, false);+ onPress={async () => {+ if (editing.isFocused) {+ safeKeyboardDismiss();+ editing.isFocused = true;}- }}- onPress={() => {- useEditorStore.getState().setSearchReplace(true);+ eSendEvent(eOpenPremiumDialog);}}/>+ ) : null}+ <ActionIcon+ name="magnify"+ color={searchReplace ? colors.accent : colors.pri}+ customStyle={{+ marginLeft: 5+ }}+ type={searchReplace ? 'grayBg' : 'transparent'}+ top={50}+ buttom={10}+ onLongPress={() => {+ if (searchReplace) {+ endSearch();+ Vibration.vibrate(5, false);+ }+ }}+ onPress={() => {+ useEditorStore.getState().setSearchReplace(true);+ }}+ />- {currentlyEditingNote && (- <ActionIcon- name="cloud-upload-outline"- color={colors.pri}- customStyle={{- marginLeft: 5- }}- top={50}- onPress={publishNote}- />- )}-+ {currentlyEditingNote && (<ActionIcon- name="attachment"+ name="cloud-upload-outline"color={colors.pri}customStyle={{marginLeft: 5}}top={50}- onPress={picker.pick}+ onPress={publishNote}/>+ )}- {deviceMode !== 'mobile' && !fullscreen ? (- <ActionIcon- name="fullscreen"- color={colors.pri}- customStyle={{- marginLeft: 5- }}- top={50}- onPress={() => {- eSendEvent(eOpenFullscreenEditor);- editing.isFullscreen = true;- }}- />- ) : null}+ <ActionIcon+ name="attachment"+ color={colors.pri}+ customStyle={{+ marginLeft: 5+ }}+ top={50}+ onPress={picker.pick}+ />+ {deviceMode !== 'mobile' && !fullscreen ? (<ActionIcon- name="dots-horizontal"+ name="fullscreen"color={colors.pri}customStyle={{marginLeft: 5}}top={50}- right={50}- onPress={showActionsheet}+ onPress={() => {+ eSendEvent(eOpenFullscreenEditor);+ editing.isFullscreen = true;+ }}/>+ ) : null}++ <ActionIcon+ name="dots-horizontal"+ color={colors.pri}+ customStyle={{+ marginLeft: 5+ }}+ top={50}+ right={50}+ onPress={showActionsheet}+ />- <ProgressCircle />- </>- </View>+ <ProgressCircle />+ </></View></View></>diff --git a/apps/mobile/src/views/Editor/EditorTitle.js b/apps/mobile/src/views/Editor/EditorTitle.jsindex 7654756f9..12718bbfa 100644--- a/apps/mobile/src/views/Editor/EditorTitle.js+++ b/apps/mobile/src/views/Editor/EditorTitle.js@@ -48,13 +48,12 @@ export const EditorTitle = () => {<Animated.Viewstyle={{opacity: opacityVal,- maxWidth: '100%',paddingLeft: 0,transform: [{translateY: translateY}- ]+ ],}}><TextInputdefaultValue={title}@@ -62,8 +61,9 @@ export const EditorTitle = () => {fontFamily: 'OpenSans-SemiBold',fontSize: SIZE.xl,color: colors.heading,- maxWidth: '100%',- padding: 0+ padding: 0,+ flexShrink:1,+ flexWrap:'wrap'}}placeholder="Note title"placeholderTextColor={colors.placeholder}diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex 95faf18c4..c646d816f 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -1,21 +1,19 @@-import React, {createRef} from 'react';-import {Platform} from 'react-native';-import {presentDialog} from '../../components/Dialog/functions';-import {useEditorStore, useMenuStore, useTagStore} from '../../provider/stores';-import {DDS} from '../../services/DeviceDetection';+import { createRef } from 'react';+import { Platform } from 'react-native';+import { presentDialog } from '../../components/Dialog/functions';+import { useEditorStore, useMenuStore, useTagStore } from '../../provider/stores';+import { DDS } from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,- eUnSubscribeEvent,- presentSheet,- ToastEvent+ eUnSubscribeEvent, ToastEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';import PremiumService from '../../services/PremiumService';-import {editing} from '../../utils';-import {COLORS_NOTE, COLOR_SCHEME} from '../../utils/Colors';-import {hexToRGBA} from '../../utils/ColorUtils';-import {db} from '../../utils/database';+import { editing } from '../../utils';+import { COLORS_NOTE, COLOR_SCHEME } from '../../utils/Colors';+import { hexToRGBA } from '../../utils/ColorUtils';+import { db } from '../../utils/database';import {eClearEditor,eOnLoadNote,@@ -24,19 +22,18 @@ import {eShowMergeDialog} from '../../utils/Events';import filesystem from '../../utils/filesystem';-import {openLinkInBrowser} from '../../utils/functions';-import {MMKV} from '../../utils/mmkv';-import {tabBarRef} from '../../utils/Refs';-import {normalize} from '../../utils/SizeUtils';-import {sleep, timeConverter} from '../../utils/TimeUtils';-import {TableCellProperties} from './TableCellProperties';-import {TableRowProperties} from './TableRowProperties';-import tiny, { safeKeyboardDismiss } from './tiny/tiny';+import { openLinkInBrowser } from '../../utils/functions';+import { MMKV } from '../../utils/mmkv';+import { tabBarRef } from '../../utils/Refs';+import { normalize } from '../../utils/SizeUtils';+import { sleep, timeConverter } from '../../utils/TimeUtils';+import { TableCellProperties } from './TableCellProperties';+import { TableRowProperties } from './TableRowProperties';+import tiny from './tiny/tiny';import {IMAGE_TOOLTIP_CONFIG,TABLE_TOOLTIP_CONFIG} from './tiny/toolbar/config';-import { focusEditor, reFocusEditor } from './tiny/toolbar/constants';export let EditorWebView = createRef();export const editorTitleInput = createRef();@@ -60,7 +57,6 @@ let webviewInit = false;let appColors = COLOR_SCHEME;let closingSession = false;-let currentEditingTimer = null;let webviewTimer = null;let requestedReload = false;let cTimeout = null;@@ -118,33 +114,13 @@ async function waitForEvent(event, caller, onend) {}export async function clearTimer(clear) {- clearTimeout(timer);- timer = null;-if (waitForContent && noteEdited) {await waitForEvent('content_event', () => {- console.log('requested content');+ console.log('requested content from edtior');tiny.call(EditorWebView, request_content);});}waitForContent = false;- if (clear) {- if (!noteEdited) return;- if (- (content?.data &&- typeof content.data === 'string' &&- content.data?.trim().length > 0) ||- (title && title?.trim().length > 0)- ) {- console.log('saving note');- await saveNote(true);- }- }-- if (currentEditingTimer) {- clearTimeout(currentEditingTimer);- currentEditingTimer = null;- }}export const CHECK_STATUS = `(function() {@@ -154,6 +130,7 @@ export const CHECK_STATUS = `(function() {sessionId:sessionId});window.ReactNativeWebView.postMessage(msg)+})();`;const request_content = `(function() {@@ -228,12 +205,11 @@ async function setNote(item) {content.type = note.content.type;} else {let data = await db.content.raw(note.contentId);- data = await db.content.insertPlaceholders(data, 'placeholder.svg');-if (!data) {content.data = '';content.type = 'tiny';} else {+ data = await db.content.insertPlaceholders(data, 'placeholder.svg');content.data = data.data;content.type = data.type;}@@ -279,9 +255,9 @@ export const loadNote = async item => {editing.movedAway = false;if (closingSession) {+ console.log('open note:', 'closing: ', closingSession);eSendEvent('loadingNote', item);await waitForEvent('session_ended');- await sleep(300);}closingSession = true;@@ -291,20 +267,27 @@ export const loadNote = async item => {if (item && item.type === 'new') {if (getNote()) {eSendEvent('loadingNote', item);- await clearEditor(true, true, true);- await sleep(1000);+ await clearEditor();}++ clearNote();eSendEvent('loadingNote');eSendEvent('updateTags');closingSession = false;disableSaving = false;- lasstEditTime = 0;- clearNote();+ lastEditTime = 0;noteEdited = false;loading_queue = null;makeSessionId(item);useEditorStore.getState().setSessionId(sessionId);await checkStatus(false);+ tiny.call(+ EditorWebView,+ `+ toggleNode(".tag-bar-parent","hide");+ clearNode(".tag-bar")`+ );+if (Platform.OS === 'android') {EditorWebView.current?.requestFocus();setTimeout(() => {@@ -316,7 +299,9 @@ export const loadNote = async item => {await sleep(200);tiny.call(EditorWebView, tiny.focusEditor);}+if (EDITOR_SETTINGS) {+ console.log('settings are present');tiny.call(EditorWebView,EDITOR_SETTINGS.directionality === 'rtl'@@ -331,20 +316,23 @@ export const loadNote = async item => {if (id === item.id && !item.forced) {console.log('note is already opened in editor');closingSession = false;+ loading_note = false;eSendEvent('loadingNote');+ await checkStatus();return;}eSendEvent('loadingNote', item);if (getNote()) {- await clearEditor(true, true, true);+ await clearEditor();}closingSession = false;disableSaving = false;noteEdited = false;- await setNote(item);webviewInit = false;editing.isFocused = false;++ await setNote(item);if (loading_queue &&(loading_queue?.id !== item?.id || loading_queue?.type === 'new')@@ -357,6 +345,8 @@ export const loadNote = async item => {}makeSessionId(item);useEditorStore.getState().setSessionId(sessionId);+ webviewInit = true;+ await loadNoteInEditor();requestedReload = true;if (await checkStatus(false)) {updateSessionStatus();@@ -410,12 +400,7 @@ function updateSessionStatus() {EditorWebView,`(function () {sessionId = '${sessionId}';- let msg = JSON.stringify({- data: true,- type: 'status',- sessionId: sessionId- });- window.ReactNativeWebView.postMessage(msg);+ reactNativeEventHandler('status', true);})();`);}@@ -507,16 +492,15 @@ export const _onMessage = async evt => {noteEdited = false;return;}-- console.log('tiny content recieved');-+ prevNoteContent = null;+ console.log('tiny content recieved', message.caller);noteEdited = true;lastEditTime = Date.now();content = {type: message.type,data: message.value};- onNoteChange();+ onNoteChange(message.caller ? 0 : 300);if (waitForContent) {eSendEvent('content_event');}@@ -580,7 +564,6 @@ export const _onMessage = async evt => {tiny.call(EditorWebView, tiny.removeMarkdown, true);}}, 300);- await loadNoteInEditor();setTimeout(() => {check_session_status();}, 1500);@@ -594,8 +577,10 @@ export const _onMessage = async evt => {return;}if (!id) return;- console.log('content not loaded');+if (message.value) {+ console.log('content not loaded', content.data);+ await checkStatus();console.log('reloading');await loadNoteInEditor();setTimeout(() => {@@ -607,6 +592,10 @@ export const _onMessage = async evt => {eSendEvent('webviewOk');webviewOK = true;break;+ case 'resetcomplete':+ console.log('reset event recieved');+ eSendEvent('resetcomplete');+ break;case 'editorSettings':EDITOR_SETTINGS = message.value;eSendEvent('editorSettingsEvent', message.value);@@ -659,58 +648,47 @@ function showTableOptionsTooltip() {eSendEvent('showTooltip', TABLE_TOOLTIP_CONFIG);}-function onNoteChange() {+function onNoteChange(wait = 300) {clearTimeout(timer);timer = null;- noteEdited = true;+ noteEdited = false;+ _sid = sessionId;+ let params = [title, id, content.data, content.type, sessionId];timer = setTimeout(() => {- if (noteEdited) {- saveNote();- }- }, 300);+ console.log('saving note', params[1], _sid, sessionId);+ saveNote(...params, _sid !== sessionId);+ }, wait);}-export async function clearEditor(- clear = true,- reset = true,- immediate = false-) {+export async function clearEditor() {try {console.log('closing session: ', closingSession);closingSession = true;- tiny.call(EditorWebView, tiny.isLoading);- if (clear) {+ await sleep(100);+ console.log('note edited: ', noteEdited);+ if (noteEdited) {+ console.log('note is edited');+ disableSaving = false;waitForContent = true;await clearTimer(true);+ await sleep(100);}disableSaving = true;+ sessionId = null;+ noteEdited = false;db.fs.cancel(getNote()?.id);clearNote();- if (cTimeout) {- clearTimeout(cTimeout);- cTimeout = null;- }- sessionId = null;- let func = async () => {- try {- console.log('reset editor', closingSession);- reset && EditorWebView.current?.reload();- await waitForEvent('resetcomplete');- editing.focusType = null;- eSendEvent('historyEvent', {- undo: 0,- redo: 0- });- saveCounter = 0;- useEditorStore.getState().setCurrentlyEditingNote(null);- } catch (e) {}- };- if (immediate) {- await func();- } else {- cTimeout = setTimeout(func, 500);- }+ tiny.call(EditorWebView, tiny.reset());+ //EditorWebView.current?.reload();+ await waitForEvent('resetcomplete');+ editing.focusType = null;+ eSendEvent('historyEvent', {+ undo: 0,+ redo: 0+ });+ saveCounter = 0;+ useEditorStore.getState().setCurrentlyEditingNote(null);} catch (e) {}disableSaving = false;@@ -780,12 +758,19 @@ async function addToCollection(id) {}}-export async function saveNote(preventUpdate) {- if (disableSaving || !noteEdited || (isSaving && !id)) return;+export async function saveNote(+ title,+ id,+ data,+ type,+ sessionId,+ preventUpdate+) {+ console.log(disableSaving, isSaving, id);+ if (disableSaving || (isSaving && !id)) return;if (preventUpdate) {noteEdited = false;}-isSaving = true;try {if (id && !db.notes.note(id)) {@@ -803,18 +788,29 @@ export async function saveNote(preventUpdate) {locked = _note.locked;}- if (!historySessionId) {+ if (!sessionId) {historySessionId = note?.dateEdited || Date.now();+ sessionId = historySessionId;+ }++ if (isContentInvalid(data)) {+ if (sessionId === historySessionId) {+ sessionId = note?.dateEdited;+ historySessionId = sessionId;+ } else {+ sessionId = note?.dateEdited;+ }+ console.log('new session begins');}let noteData = {title,content: {- data: content.data,- type: content.type+ data: data,+ type: type},id: id,- sessionId: historySessionId+ sessionId: isContentInvalid(data) ? null : sessionId};console.log(@@ -846,9 +842,12 @@ export async function saveNote(preventUpdate) {post('titleplaceholder', db.notes.note(noteId)?.data?.title || '');}- useEditorStore.getState().setCurrentlyEditingNote(noteId);await setNoteInEditorAfterSaving(id, noteId);saveCounter++;+ id = noteId;+ setTimeout(() => {+ useEditorStore.getState().setCurrentlyEditingNote(noteId);+ });}} else {noteData.contentId = note.contentId;@@ -860,8 +859,9 @@ export async function saveNote(preventUpdate) {Navigation.routeNames.Favorites,Navigation.routeNames.Notes]);- let n = db.notes.note(id)?.data?.dateEdited;+lastEditTime = n + 10;+ let n = db.notes.note(id)?.data?.dateEdited;tiny.call(EditorWebView,tiny.updateDateEdited(n ? timeConverter(n) : '')@@ -881,7 +881,8 @@ export async function saveNote(preventUpdate) {if (password && password.trim()) {try {await db.vault.unlock(password);- await saveNote();+ noteEdited = true;+ onNoteChange(0);} catch (e) {console.log(e);return false;@@ -964,12 +965,14 @@ export const presentResolveConflictDialog = _note => {};const loadNoteInEditor = async (keepHistory = true) => {+ console.log(webviewInit, 'ready?');if (!webviewInit) return;try {if (note?.id) {eSendEvent('updateTags');post('title', title);intent = false;+if (!content || !content.data || content?.data?.length === 0) {tiny.call(EditorWebView,@@ -986,6 +989,7 @@ const loadNoteInEditor = async (keepHistory = true) => {`);} else {+ console.log('posting html');post('html', content.data);}if (id) {@@ -1001,13 +1005,14 @@ const loadNoteInEditor = async (keepHistory = true) => {} else {await restoreEditorState();}- loadingNote = null;+if (keepHistory) {tiny.call(EditorWebView, tiny.clearHistory);}} catch (e) {}disableSaving = false;+ check_session_status();};export async function updateNoteInEditor() {diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.jsindex b0bf6cdc4..3a15bb231 100755--- a/apps/mobile/src/views/Editor/index.js+++ b/apps/mobile/src/views/Editor/index.js@@ -1,17 +1,18 @@-import React, { useEffect, useState } from 'react';-import { Platform, View } from 'react-native';+import React, {useEffect, useState} from 'react';+import {Platform, View} from 'react-native';import WebView from 'react-native-webview';-import { notesnook } from '../../../e2e/test.ids';-import { useEditorStore, useUserStore } from '../../provider/stores';+import {notesnook} from '../../../e2e/test.ids';+import {useEditorStore, useUserStore} from '../../provider/stores';+import { DDS } from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,eUnSubscribeEvent} from '../../services/EventManager';-import { getCurrentColors } from '../../utils/Colors';-import { eOnLoadNote } from '../../utils/Events';-import { tabBarRef } from '../../utils/Refs';-import { sleep } from '../../utils/TimeUtils';+import {getCurrentColors} from '../../utils/Colors';+import {eOnLoadNote} from '../../utils/Events';+import {tabBarRef} from '../../utils/Refs';+import {sleep} from '../../utils/TimeUtils';import EditorHeader from './EditorHeader';import {disableEditing,@@ -57,7 +58,7 @@ const Editor = React.memo(setResetting(true);await sleep(10);setResetting(false);- if (tabBarRef.current?.scrollOffset === 0 ) {+ if (!DDS.isTab && tabBarRef.current?.page === 0) {console.log('Editor out of bounds');return;}@@ -66,11 +67,7 @@ const Editor = React.memo(}if (getNote()) {-- eSendEvent(- eOnLoadNote,- {...getNote(), forced: true}- );+ eSendEvent(eOnLoadNote, {...getNote(), forced: true});}console.log('resetting editor');};@@ -89,7 +86,7 @@ const Editor = React.memo(width: '100%',backgroundColor: 'transparent',flexGrow: 1,- flex: 1,+ flex: 1}}><EditorHeader /><WebViewdiff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.jsindex badd42b27..f754dab38 100644--- a/apps/mobile/src/views/Editor/tiny/tiny.js+++ b/apps/mobile/src/views/Editor/tiny/tiny.js@@ -2,21 +2,27 @@ import {Platform} from 'react-native';import {editing} from '../../../utils';import {EditorWebView, getWebviewInit, post, textInput} from '../Functions';-const reset = `-isLoading = true;+const reset =(id) => `+sessionId = null;document.getElementById("titleInput").value = '';-autosize();-window.prevContent = "";-globalThis.isClearingNoteData = true;-tinymce.activeEditor.setHTML('');+document.getElementById("titleInput").placeholder = "Note title";+tinymce.activeEditor.mode.set('readonly');+tinymce.activeEditor.clearContent();+tinymce.activeEditor.setHTML("<p><br/></p>");+editor.dom.setAttrib(editor.dom.doc.body, 'data-mce-placeholder', 'Start writing your note here');+editor.dom.setAttrib(editor.dom.doc.body, 'aria-placeholder', 'Start writing your note here');+renderChildernInNode([], ".tag-bar");tinymce.activeEditor.undoManager.clear();-info = document.querySelector(infoBar);-info.querySelector('#infosaved').innerText = "";-info.querySelector('#infodate').innerText = "";-info.querySelector('#infowords').innerText = ""-updateInfoBar()+document.querySelector('#infosaved').innerText = "";+document.querySelector('#infodate').innerText = "";+document.querySelector('#infowords').innerText = "0 words"+updateInfoBar();+reactNativeEventHandler('resetcomplete');+tinymce.activeEditor.mode.set('design');document.activeElement.blur();window.blur();+toggleNode(".tag-bar-parent","hide");+clearNode(".tag-bar");`;const removeMarkdown = `diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/picker.js b/apps/mobile/src/views/Editor/tiny/toolbar/picker.jsindex 7b8a5863a..0dcaaceff 100644--- a/apps/mobile/src/views/Editor/tiny/toolbar/picker.js+++ b/apps/mobile/src/views/Editor/tiny/toolbar/picker.js@@ -62,9 +62,8 @@ const file = async () => {if (Platform.OS == 'ios') {options.copyTo = 'cachesDirectory';}-+ console.log('generate key for attachment');let key = await db.attachments.generateKey();-console.log('generated key for attachments: ', key);let file;try {