Skip to content

Commit

Permalink
Merge pull request #7644 from weseek/fix/cursor-reset-after-updating-…
Browse files Browse the repository at this point in the history
…with-shortcut-key

fix: Cursor resetting occurs after updating with the built-in editor
  • Loading branch information
yuki-takei authored May 11, 2023
2 parents 6ace147 + 4733a55 commit 3a48dca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions apps/app/src/client/services/page-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ export const useSaveOrUpdate = (): SaveOrUpdateFunction => {
}, [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 { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
const { setRemoteLatestPageData } = useSetRemoteLatestPageData();
Expand All @@ -198,7 +202,12 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null): (() => P

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 = {
remoteRevisionId: updatedPage.revision._id,
Expand All @@ -210,7 +219,9 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null): (() => P
};

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> => {
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const PageEditor = React.memo((): JSX.Element => {
const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
const saveOrUpdate = useSaveOrUpdate();

const updateStateAfterSave = useUpdateStateAfterSave(pageId);
const updateStateAfterSave = useUpdateStateAfterSave(pageId, { supressEditingMarkdownMutation: true });

const currentRevisionId = currentPage?.revision?._id;

Expand Down

0 comments on commit 3a48dca

Please sign in to comment.