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

feat: Each user can undo/redo only their own input #8312

Merged
merged 1 commit into from
Dec 11, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor Author

Choose a reason for hiding this comment

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

keymap.of(yUndoManagerKeymap) の追加は yjs 関連のコードとして use-collaborative-editor-mode 内に収めることも考えましたが、react-codemirror の設定値をここで history: false するので default extensions としてここで追加するようにしました。

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { keymap, EditorView } from '@codemirror/view';
import { tags } from '@lezer/highlight';
import { useCodeMirror, type UseCodeMirror } from '@uiw/react-codemirror';
import deepmerge from 'ts-deepmerge';
// see: https://github.com/yjs/y-codemirror.next#example
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { yUndoManagerKeymap } from 'y-codemirror.next';

import { emojiAutocompletionSettings } from '../../extensions/emojiAutocompletionSettings';

Expand Down Expand Up @@ -56,6 +60,7 @@ const defaultExtensions: Extension[] = [
syntaxHighlighting(markdownHighlighting),
Prec.lowest(syntaxHighlighting(defaultHighlightStyle)),
emojiAutocompletionSettings,
keymap.of(yUndoManagerKeymap),
];


Expand All @@ -78,6 +83,8 @@ export const useCodeMirrorEditor = (props?: UseCodeMirror): UseCodeMirrorEditor
basicSetup: {
defaultKeymap: false,
dropCursor: false,
// Disabled react-codemirror history for Y.UndoManager
history: false,
},
// ------- End -------
},
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/stores/use-collaborative-editor-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const useCollaborativeEditorMode = (
setProvider(socketIOProvider);
};

const attachYDocExtensionsToCodeMirror = () => {
const setupYDocExtensions = () => {
if (ydoc == null || provider == null) {
return;
}
Expand Down Expand Up @@ -116,6 +116,6 @@ export const useCollaborativeEditorMode = (
useEffect(cleanupYDocAndProvider, [cPageId, pageId, provider, socket, ydoc]);
useEffect(setupYDoc, [provider, ydoc]);
useEffect(setupProvider, [initialValue, pageId, provider, socket, userName, ydoc]);
useEffect(attachYDocExtensionsToCodeMirror, [codeMirrorEditor, provider, ydoc]);
useEffect(setupYDocExtensions, [codeMirrorEditor, provider, ydoc]);
useEffect(initializeEditor, [codeMirrorEditor, isInit, onOpenEditor, ydoc]);
};