Skip to content

Commit

Permalink
fix(merge): fix extensions props issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 2, 2023
1 parent 250cf04 commit edef72d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion merge/src/Internal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useImperativeHandle, useMemo, useRef, memo } from 'react';
import { EditorStateConfig, Extension, StateEffect, Annotation } from '@codemirror/state';
import { MergeView, MergeConfig } from '@codemirror/merge';
import { useStore } from './store';
import { CodeMirrorMergeProps } from './';
Expand All @@ -24,7 +25,7 @@ export const Internal = React.forwardRef((props: CodeMirrorMergeProps, ref?: Rea
const editor = useRef<HTMLDivElement>(null);
useImperativeHandle(ref, () => ({ container: editor.current, view }), [editor, view]);
useEffect(() => {
if (!view && editor.current && original && modified) {
if (!view && editor.current && original?.extensions && modified?.extensions) {
const opts = { orientation, revertControls, highlightChanges, gutter, collapseUnchanged, renderRevertControl };
const viewDefault = new MergeView({
a: original,
Expand Down
5 changes: 5 additions & 0 deletions merge/src/Modified.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const Modified = (props: ModifiedProps): JSX.Element | null => {
});
const extensionsData = [updateListener, ...defaultExtensions, ...extensions];
const data: EditorStateConfig = { extensions: [...extensionsData] };

useEffect(() => {
dispatch!({ modified: { doc: props.value, selection: props.selection, ...data } });
}, []);

useEffect(() => {
if (modified?.doc !== props.value && view) {
data.doc = props.value;
Expand Down
6 changes: 6 additions & 0 deletions merge/src/Original.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const Original = (props: OriginalProps): JSX.Element | null => {
});
const extensionsData = [updateListener, ...defaultExtensions, ...extensions];
const data: EditorStateConfig = { extensions: [...extensionsData] };

useEffect(() => {
dispatch!({ original: { doc: props.value, selection: props.selection, ...data } });
}, []);

useEffect(() => {
if (original?.doc !== props.value && view) {
data.doc = props.value;
Expand All @@ -41,6 +46,7 @@ export const Original = (props: OriginalProps): JSX.Element | null => {
view?.a.dispatch({
changes: { from: 0, to: (originalDoc || '').length, insert: props.value || '' },
effects: StateEffect.appendConfig.of([...extensionsData]),
annotations: [External.of(true)],
});
}
}
Expand Down

0 comments on commit edef72d

Please sign in to comment.