Skip to content

Commit

Permalink
fix editor reloading content and extensions when typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcv8000 committed Nov 8, 2023
1 parent 7218e49 commit ca8d911
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/renderer/src/components/Views/Editor/EditorView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
import "./styles.scss";
import { Container, Paper } from "@mantine/core";
import { Page } from "common/Save";
import { useContext, useEffect } from "react";
import { useContext, useEffect, useMemo } from "react";
import { AppContext } from "types/AppStore";
import { Editor, EditorContent, useEditor } from "@tiptap/react";
import Toolbar from "./Toolbar/Toolbar";
Expand All @@ -17,14 17,22 @@ type Props = {
export function EditorView({ page, setEditorRef }: Props) {
const appContext = useContext(AppContext);

const editor = useEditor(
{
extensions: extensions({
const _extensions = useMemo(
() =>
extensions({
useTypography: appContext.prefs.editor.useTypographyExtension,
tabSize: appContext.prefs.editor.tabSize
}),
[appContext.prefs.editor.tabSize, appContext.prefs.editor.useTypographyExtension]
);

const content = useMemo(() => JSON.parse(window.api.loadPage(page.fileName)), [page.fileName]);

const editor = useEditor(
{
extensions: _extensions,
autofocus: true,
content: JSON.parse(window.api.loadPage(page.fileName))
content: content
},
[page.id]
);
Expand Down

0 comments on commit ca8d911

Please sign in to comment.