Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Editor not resetting when the same markdown #7625

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/app/src/components/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,14 @@ const PageEditor = React.memo((): JSX.Element => {
}
}, [initialValue, isIndentSizeForced, mutateCurrentIndentSize]);

// when transitioning to a different page, if the initialValue is the same,
// UnControlled CodeMirror value does not reset, so explicitly set the value to initialValue
useEffect(() => {
if (currentPagePath != null) {
editorRef.current?.setValue(initialValue);
}
}, [currentPagePath, initialValue]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ページが変更されても CodeMirror に行き渡る initialValue が同じだと CodeMirror のコード値は変わらないので、明示的に初期値に更新


if (!isEditable) {
return <></>;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/PageEditor/CodeMirrorEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class CodeMirrorEditor extends AbstractEditor {

changeHandler(editor, data, value) {
if (this.props.onChange != null) {
const isClean = data.origin == null || editor.isClean();
const isClean = data.origin == null || editor.isClean() || value === this.props.value;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

値が同じままの際は clean とする。
(今回の実装で isEnabledUnsavedWarning が true とならないように追記)

this.props.onChange(value, isClean);
}

Expand Down