Skip to content

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

fix editor

ammarahm-edf6bff1c9228a
diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsx
index aea15dca1..010282836 100644
--- a/packages/editor-mobile/src/components/editor.tsx
+++ b/packages/editor-mobile/src/components/editor.tsx
@@ -6,7 +6,7 @@ import {
useTiptap,
} from "@streetwriters/editor";
import { useTheme } from "@streetwriters/theme";
-import { useLayoutEffect, useRef, useState } from "react";
+import { useCallback, useLayoutEffect, useRef, useState } from "react";
import { useEditorController } from "../hooks/useEditorController";
import { useSettings } from "../hooks/useSettings";
import { useEditorThemeStore } from "../state/theme";
@@ -86,7 +86,7 @@ const Tiptap = () => {
global.editorController.contentChange(editor as Editor);
},
onSelectionUpdate: (props) => {
- global.editorController.selectionChange(props.editor as Editor);
+ props.transaction.scrollIntoView();
},
onOpenAttachmentPicker: (editor, type) => {
global.editorController.openFilePicker(type);
@@ -109,12 +109,12 @@ const Tiptap = () => {
[layout, settings.readonly, tick]
);
- const update = () => {
+ const update = useCallback(() => {
setTick((tick) => tick + 1);
- controller.setTitlePlaceholder("Note title");
- };
+ globalThis.editorController.setTitlePlaceholder("Note title");
+ }, []);
- const controller = useEditorController(_editor, update);
+ const controller = useEditorController(update);
const controllerRef = useRef(controller);
globalThis.editorController = controller;
globalThis.editor = _editor;
diff --git a/packages/editor-mobile/src/hooks/useEditorController.ts b/packages/editor-mobile/src/hooks/useEditorController.ts
index c73a45e4c..fcd125f2b 100644
--- a/packages/editor-mobile/src/hooks/useEditorController.ts
+++ b/packages/editor-mobile/src/hooks/useEditorController.ts
@@ -45,10 +45,7 @@ export type EditorController = {
setTitlePlaceholder: React.Dispatch<React.SetStateAction<string>>;
};
-export function useEditorController(
- editor: Editor | null,
- update: () => void
-): EditorController {
+export function useEditorController(update: () => void): EditorController {
const [title, setTitle] = useState("");
const [titlePlaceholder, setTitlePlaceholder] = useState("Note title");
const htmlContentRef = useRef<string | null>(null);
@@ -57,43 +54,11 @@ export function useEditorController(
change: null,
});
- const selectionChange = useCallback((editor: Editor) => {
- // if (!editor) return;
- // timers.current.selectionChange = timerFn(
- // () => {
- // let selection: Selection = {};
- // let { view, state, schema } = editor;
- // let { to, from } = view.state.selection;
- // selection.attributes = {
- // text: state.doc.textBetween(from, to, ""),
- // length: to - from,
- // };
- // let marks = Object.keys(schema.marks);
- // let nodes = Object.keys(schema.nodes);
- // for (let mark of marks) {
- // if (!editor.isActive(mark)) continue;
- // selection[mark] = {
- // attributes: editor.getAttributes(mark),
- // type: "mark",
- // };
- // }
- // for (let node of nodes) {
- // if (!editor.isActive(node)) continue;
- // selection[node] = {
- // attributes: editor.getAttributes(node),
- // type: "node",
- // };
- // }
- // post(EventTypes.selection, selection);
- // },
- // 500,
- // timers.current?.selectionChange
- // );
- }, []);
+ const selectionChange = useCallback((editor: Editor) => {}, []);
- const titleChange = (title: string) => {
+ const titleChange = useCallback((title: string) => {
post(EventTypes.title, title);
- };
+ }, []);
const contentChange = useCallback((editor: Editor) => {
if (!editor) return;
@@ -114,9 +79,9 @@ export function useEditorController(
[]
);
- const onUpdate = () => {
+ const onUpdate = useCallback(() => {
update();
- };
+ }, [update]);
const onMessage = useCallback(
(data: Event) => {
@@ -153,13 +118,6 @@ export function useEditorController(
[update]
);
- // useEffect(() => {
- // post(EventTypes.history, {
- // undo: false, // editor?.can().undo(),
- // redo: false, // editor?.can().redo(),
- // });
- // }, [editor]);
-
useEffect(() => {
if (!isReactNative()) return; // Subscribe only in react native webview.
let isSafari = navigator.vendor.match(/apple/i);
@@ -168,7 +126,7 @@ export function useEditorController(
//@ts-ignore
root = window;
}
-
+ console.log("recreating messaging");
root.addEventListener("message", onMessage);
return () => {
@@ -181,7 +139,6 @@ export function useEditorController(
}, []);
const downloadAttachment = useCallback((attachment: Attachment) => {
- alert("downloadAttachment" + attachment.hash);
post(EventTypes.download, attachment);
}, []);