Преглед изворни кода

Merge pull request #7644 from weseek/fix/cursor-reset-after-updating-with-shortcut-key

fix: Cursor resetting occurs after updating with the built-in editor
Yuki Takei пре 2 година
родитељ
комит
3a48dcafca
2 измењених фајлова са 15 додато и 4 уклоњено
  1. 14 3
      apps/app/src/client/services/page-operation.ts
  2. 1 1
      apps/app/src/components/PageEditor.tsx

+ 14 - 3
apps/app/src/client/services/page-operation.ts

@@ -176,7 +176,11 @@ export const useSaveOrUpdate = (): SaveOrUpdateFunction => {
   }, [mutateIsEnabledUnsavedWarning]);
   }, [mutateIsEnabledUnsavedWarning]);
 };
 };
 
 
-export const useUpdateStateAfterSave = (pageId: string|undefined|null): (() => Promise<void>) | undefined => {
+export type UpdateStateAfterSaveOption = {
+  supressEditingMarkdownMutation: boolean,
+}
+
+export const useUpdateStateAfterSave = (pageId: string|undefined|null, opts?: UpdateStateAfterSaveOption): (() => Promise<void>) | undefined => {
   const { mutate: mutateCurrentPageId } = useCurrentPageId();
   const { mutate: mutateCurrentPageId } = useCurrentPageId();
   const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
   const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
   const { setRemoteLatestPageData } = useSetRemoteLatestPageData();
   const { setRemoteLatestPageData } = useSetRemoteLatestPageData();
@@ -198,7 +202,12 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null): (() => P
 
 
     if (updatedPage == null) { return }
     if (updatedPage == null) { return }
 
 
-    mutateEditingMarkdown(updatedPage.revision.body);
+    // supress to mutate only when updated from built-in editor
+    // and see: https://github.com/weseek/growi/pull/7118
+    const supressEditingMarkdownMutation = opts?.supressEditingMarkdownMutation ?? false;
+    if (!supressEditingMarkdownMutation) {
+      mutateEditingMarkdown(updatedPage.revision.body);
+    }
 
 
     const remoterevisionData = {
     const remoterevisionData = {
       remoteRevisionId: updatedPage.revision._id,
       remoteRevisionId: updatedPage.revision._id,
@@ -210,7 +219,9 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null): (() => P
     };
     };
 
 
     setRemoteLatestPageData(remoterevisionData);
     setRemoteLatestPageData(remoterevisionData);
-  }, [mutateCurrentPage, mutateCurrentPageId, mutateEditingMarkdown, mutateTagsInfo, pageId, setRemoteLatestPageData, syncTagsInfoForEditor]);
+  },
+  // eslint-disable-next-line max-len
+  [pageId, mutateTagsInfo, syncTagsInfoForEditor, mutateCurrentPageId, mutateCurrentPage, opts?.supressEditingMarkdownMutation, setRemoteLatestPageData, mutateEditingMarkdown]);
 };
 };
 
 
 export const unlink = async(path: string): Promise<void> => {
 export const unlink = async(path: string): Promise<void> => {

+ 1 - 1
apps/app/src/components/PageEditor.tsx

@@ -108,7 +108,7 @@ const PageEditor = React.memo((): JSX.Element => {
   const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
   const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
   const saveOrUpdate = useSaveOrUpdate();
   const saveOrUpdate = useSaveOrUpdate();
 
 
-  const updateStateAfterSave = useUpdateStateAfterSave(pageId);
+  const updateStateAfterSave = useUpdateStateAfterSave(pageId, { supressEditingMarkdownMutation: true });
 
 
   const currentRevisionId = currentPage?.revision?._id;
   const currentRevisionId = currentPage?.revision?._id;