Skip to content

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

editor: update word count immediately after note is loaded

ammarahm-edd838c2e8adc8
diff --git a/packages/editor-mobile/src/components/statusbar.tsx b/packages/editor-mobile/src/components/statusbar.tsx
index bfaec4236..ffce51478 100644
--- a/packages/editor-mobile/src/components/statusbar.tsx
+++ b/packages/editor-mobile/src/components/statusbar.tsx
@@ -33,7 +33,12 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
const currentWords = useRef(words);
const interval = useRef(0);
const statusBar = useRef({
- set: setStatus
+ set: setStatus,
+ updateWords: () => {
+ const words = getTotalWords(editor as Editor) + " words";
+ if (currentWords.current === words) return;
+ setWords(words);
+ }
});
globalThis.statusBar = statusBar;
@@ -66,11 +71,10 @@ function StatusBar({ container }: { container: RefObject<HTMLDivElement> }) {
useEffect(() => {
clearInterval(interval.current);
- interval.current = setInterval(() => {
- const words = getTotalWords(editor as Editor) + " words";
- if (currentWords.current === words) return;
- setWords(words);
- }, 3000) as unknown as number;
+ interval.current = setInterval(
+ statusBar.current.updateWords,
+ 3000
+ ) as unknown as number;
return () => {
clearInterval(interval.current);
};
diff --git a/packages/editor-mobile/src/hooks/useEditorController.ts b/packages/editor-mobile/src/hooks/useEditorController.ts
index 86c2fd29a..d252268e1 100644
--- a/packages/editor-mobile/src/hooks/useEditorController.ts
+++ b/packages/editor-mobile/src/hooks/useEditorController.ts
@@ -123,12 +123,13 @@ export function useEditorController(update: () => void): EditorController {
from,
to
});
-
+ statusBar.current?.updateWords();
break;
}
case "native:html":
htmlContentRef.current = value;
update();
+ statusBar.current?.updateWords();
break;
case "native:theme":
useEditorThemeStore.getState().setColors(message.value);
@@ -156,7 +157,6 @@ export function useEditorController(update: () => void): EditorController {
if (isSafari) {
root = window;
}
- console.log("recreating messaging");
root.addEventListener("message", onMessage);
return () => {
diff --git a/packages/editor-mobile/src/utils/index.ts b/packages/editor-mobile/src/utils/index.ts
index 286bc262d..82a70370e 100644
--- a/packages/editor-mobile/src/utils/index.ts
+++ b/packages/editor-mobile/src/utils/index.ts
@@ -51,6 +51,7 @@ declare global {
saved: string;
}>
>;
+ updateWords: () => void;
}>;
var __PLATFORM__: "ios" | "android";
var readonly: boolean;