Skip to content

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

web: refresh editor on changing editor options

Abdullah Attad98be849e33f
diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsx
index a1e04e9bb..0efdbccee 100644
--- a/apps/web/src/components/editor/tiptap.tsx
+++ b/apps/web/src/components/editor/tiptap.tsx
@@ -61,6 +61,7 @@ import { parseInternalLink } from "@notesnook/core";
import Skeleton from "react-loading-skeleton";
import useMobile from "../../hooks/use-mobile";
import useTablet from "../../hooks/use-tablet";
+import { TimeFormat } from "@notesnook/core/dist/utils/date";
export type OnChangeHandler = (
content: () => string,
@@ -95,6 +96,11 @@ type TipTapProps = {
downloadOptions?: DownloadOptions;
fontSize: number;
fontFamily: string;
+
+ doubleSpacedLines: boolean;
+ dateFormat: string;
+ timeFormat: TimeFormat;
+ markdownShortcuts: boolean;
};
function updateWordCount(id: string, content: () => Fragment) {
@@ -133,19 +139,15 @@ function TipTap(props: TipTapProps) {
isTablet,
downloadOptions,
fontSize,
- fontFamily
+ fontFamily,
+ doubleSpacedLines,
+ dateFormat,
+ timeFormat,
+ markdownShortcuts
} = props;
const isUserPremium = useIsUserPremium();
const autoSave = useRef(true);
- const doubleSpacedLines = useSettingsStore(
- (store) => store.doubleSpacedParagraphs
- );
- const dateFormat = useSettingsStore((store) => store.dateFormat);
- const timeFormat = useSettingsStore((store) => store.timeFormat);
- const markdownShortcuts = useSettingsStore(
- (store) => store.markdownShortcuts
- );
const { toolbarConfig } = useToolbarConfig();
usePermissionHandler({
@@ -382,7 +384,17 @@ function TipTap(props: TipTapProps) {
function TiptapWrapper(
props: PropsWithChildren<
- Omit<TipTapProps, "editorContainer" | "theme" | "fontSize" | "fontFamily">
+ Omit<
+ TipTapProps,
+ | "editorContainer"
+ | "theme"
+ | "fontSize"
+ | "fontFamily"
+ | "doubleSpacedLines"
+ | "dateFormat"
+ | "timeFormat"
+ | "markdownShortcuts"
+ >
> & {
isHydrating?: boolean;
}
@@ -391,6 +403,14 @@ function TiptapWrapper(
const theme = useThemeStore((store) =>
store.colorScheme === "dark" ? store.darkTheme : store.lightTheme
);
+ const doubleSpacedLines = useSettingsStore(
+ (store) => store.doubleSpacedParagraphs
+ );
+ const dateFormat = useSettingsStore((store) => store.dateFormat);
+ const timeFormat = useSettingsStore((store) => store.timeFormat);
+ const markdownShortcuts = useSettingsStore(
+ (store) => store.markdownShortcuts
+ );
const containerRef = useRef<HTMLDivElement>(null);
const editorContainerRef = useRef<HTMLDivElement>();
const { editorConfig } = useEditorConfig();
@@ -435,9 +455,14 @@ function TiptapWrapper(
}}
>
<TipTap
+ key={`tiptap-${props.id}-${doubleSpacedLines}-${dateFormat}-${timeFormat}-${markdownShortcuts}`}
{...props}
isMobile={isMobile}
isTablet={isTablet}
+ doubleSpacedLines={doubleSpacedLines}
+ dateFormat={dateFormat}
+ timeFormat={timeFormat}
+ markdownShortcuts={markdownShortcuts}
onLoad={(editor) => {
if (!isHydrating) {
onLoad?.(editor);
diff --git a/packages/editor/src/extensions/task-list/task-list.ts b/packages/editor/src/extensions/task-list/task-list.ts
index 762a464c5..bc62f4aaa 100644
--- a/packages/editor/src/extensions/task-list/task-list.ts
+++ b/packages/editor/src/extensions/task-list/task-list.ts
@@ -242,7 +242,9 @@ export const TaskListNode = TaskList.extend({
tr.setMeta("addToHistory", false);
try {
view.dispatch(tr);
- } catch (e) {}
+ } catch (e) {
+ // ignore
+ }
return {};
},
appendTransaction(transactions, oldState, newState) {
diff --git a/packages/editor/src/hooks/use-editor.ts b/packages/editor/src/hooks/use-editor.ts
index 10669a0c3..72596a53f 100644
--- a/packages/editor/src/hooks/use-editor.ts
+++ b/packages/editor/src/hooks/use-editor.ts
@@ -50,7 +50,6 @@ export const useEditor = (
const oldContent = editor.options.content;
editor.options = { ...editor.options, ...options };
- (editor as any).createExtensionManager();
options.onBeforeCreate?.({ editor });
// we try very hard not to create a new editor, instead
// we just update the props & other things. This is dangerous but faster
@@ -81,19 +80,8 @@ export const useEditor = (
})
);
if (oldIsFocused && !editor.isFocused) editor.commands.focus();
- } else {
- editor.view.updateState(
- editor.state.reconfigure({ plugins: editor.extensionManager.plugins })
- );
}
options.onCreate?.({ editor: editor });
- editor.on("create", editor.options.onCreate);
- editor.on("update", editor.options.onUpdate);
- editor.on("selectionUpdate", editor.options.onSelectionUpdate);
- editor.on("transaction", editor.options.onTransaction);
- editor.on("focus", editor.options.onFocus);
- editor.on("blur", editor.options.onBlur);
- editor.on("destroy", editor.options.onDestroy);
function onTransaction({ editor }: { editor: TiptapEditor }) {
editorRef.current = editor;