;
},
- element: !layout ? undefined : contentRef.current || undefined,
+ element: getContentDiv(),
editable: !settings.readonly,
editorProps: {
editable: () => !settings.readonly
@@ -115,11 +114,11 @@ const Tiptap = ({ settings }: { settings: Settings }) => {
globalThis.editorControllers[tab.id]?.copyToClipboard(text);
},
onSelectionUpdate: () => {
- if (tab.noteId) {
- const noteId = tab.noteId;
+ if (tabRef.current.noteId) {
+ const noteId = tabRef.current.noteId;
clearTimeout(noteStateUpdateTimer.current);
noteStateUpdateTimer.current = setTimeout(() => {
- if (tab.noteId !== noteId) return;
+ if (tabRef.current.noteId !== noteId) return;
const { to, from } =
editors[tabRef.current?.id]?.state.selection || {};
useTabStore.getState().setNoteState(noteId, {
@@ -135,17 +134,22 @@ const Tiptap = ({ settings }: { settings: Settings }) => {
dateFormat: settings.dateFormat,
timeFormat: settings.timeFormat as "12-hour" | "24-hour" | undefined,
enableInputRules: settings.markdownShortcuts
- },
- [
- layout,
- settings.readonly,
- tick,
- settings.doubleSpacedLines,
- settings.markdownShortcuts
- ]
- );
+ };
+ }, [
+ getContentDiv,
+ settings.readonly,
+ settings.doubleSpacedLines,
+ settings.corsProxy,
+ settings.dateFormat,
+ settings.timeFormat,
+ settings.markdownShortcuts,
+ tab.id
+ ]);
+
+ const _editor = useTiptap(tiptapOptions, [tiptapOptions]);
const update = useCallback(() => {
+ logger("info", "update content");
setTick((tick) => tick + 1);
setTimeout(() => {
const noteState = tabRef.current.noteId
@@ -189,7 +193,10 @@ const Tiptap = ({ settings }: { settings: Settings }) => {
globalThis.editors[tab.id] = _editor;
useLayoutEffect(() => {
- setLayout(true);
+ if (!getContentDiv().parentElement) {
+ contentPlaceholderRef.current?.appendChild(getContentDiv());
+ }
+
const updateScrollPosition = (state: TabStore) => {
if (isFocusedRef.current) return;
if (state.currentTab === tabRef.current.id) {
@@ -396,12 +403,7 @@ const Tiptap = ({ settings }: { settings: Settings }) => {
) : null}
-
+
{
@@ -420,14 +422,15 @@ const Tiptap = ({ settings }: { settings: Settings }) => {
/>
- {!layout || tab.locked ? null : (
+ {tab.locked ? null : (
{
);
};
-const ContentDiv = memo(
- forwardRef<
- HTMLDivElement,
- { padding: number; fontSize: number; fontFamily: string }
- >((props, ref) => {
- const { colors } = useThemeColors("editor");
- return (
-
- );
- }),
- (prev, next) => {
- if (prev.fontSize !== next.fontSize || prev.fontFamily !== next.fontFamily)
- return false;
- return true;
- }
-);
-
const TiptapProvider = (): JSX.Element => {
const settings = useSettings();
-
+ const { colors } = useThemeColors("editor");
+ const contentRef = useRef();
return (
-
+ {
+ if (contentRef.current) {
+ logger("info", "return content");
+ return contentRef.current;
+ }
+ logger("info", "new content");
+ const editorContainer = document.createElement("div");
+ editorContainer.classList.add("selectable");
+ editorContainer.style.flex = "1";
+ editorContainer.style.cursor = "text";
+ editorContainer.style.padding = "0px 12px";
+ editorContainer.style.color =
+ colors?.primary?.paragraph || colors.primary.paragraph;
+ editorContainer.style.paddingBottom = `150px`;
+ editorContainer.style.fontSize = `${settings.fontSize}px`;
+ editorContainer.style.fontFamily =
+ getFontById(settings.fontFamily)?.font || "sans-serif";
+ contentRef.current = editorContainer;
+ return editorContainer;
+ }}
+ />
);
};
diff --git a/packages/editor-mobile/src/index.tsx b/packages/editor-mobile/src/index.tsx
index 4e98edead..c52af72df 100644
--- a/packages/editor-mobile/src/index.tsx
+++ b/packages/editor-mobile/src/index.tsx
@@ -29,9 +29,5 @@ import "@notesnook/editor/styles/styles.css";
const rootElement = document.getElementById("root");
if (rootElement) {
const root = createRoot(rootElement);
- root.render(
-
-
-
- );
+ root.render();
}
diff --git a/packages/editor/src/hooks/use-editor.ts b/packages/editor/src/hooks/use-editor.ts
index c577a8f3a..537d1c1a3 100644
--- a/packages/editor/src/hooks/use-editor.ts
+++ b/packages/editor/src/hooks/use-editor.ts
@@ -39,7 +39,7 @@ export const useEditor = (
) => {
const editor = useMemo(() => {
const instance = new Editor(options);
- if (instance && !Object.hasOwn(instance, "current")) {
+ if (instance && typeof instance.current === "undefined") {
Object.defineProperty(instance, "current", {
get: () => editorRef.current
});
@@ -59,7 +59,10 @@ export const useEditor = (
// than creating a new editor
// This part below is copied from @tiptap/core
if (options.editorProps) editor.view.setProps(options.editorProps);
- if (options.content && options.content !== editor.options.content) {
+ if (
+ options.content !== undefined &&
+ options.content !== editor.options.content
+ ) {
const doc = createDocument(
options.content,
editor.schema,