Skip to content

Commit b269fd1

Browse files
authored
revert "feat: Add a way to provide serialized initial state for the editor (#376)" (#377)
This reverts commit 35f406f.
1 parent 35f406f commit b269fd1

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

core/src/index.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ export interface ReactCodeMirrorProps
6969
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
7070
*/
7171
root?: ShadowRoot | Document;
72-
/**
73-
* Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function
74-
*/
75-
initialState?: {
76-
json: any;
77-
fields?: Object<StateField<any>>;
78-
};
7972
}
8073

8174
export interface ReactCodeMirrorRef {
@@ -108,7 +101,6 @@ const ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((pr
108101
editable,
109102
readOnly,
110103
root,
111-
initialState,
112104
...other
113105
} = props;
114106
const editor = useRef<HTMLDivElement>(null);
@@ -135,7 +127,6 @@ const ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((pr
135127
onCreateEditor,
136128
onUpdate,
137129
extensions,
138-
initialState,
139130
});
140131

141132
useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [

core/src/useCodeMirror.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export function useCodeMirror(props: UseCodeMirror) {
3434
indentWithTab: defaultIndentWithTab = true,
3535
basicSetup: defaultBasicSetup = true,
3636
root,
37-
initialState,
3837
} = props;
3938
const [container, setContainer] = useState<HTMLDivElement>();
4039
const [view, setView] = useState<EditorView>();
@@ -110,14 +109,11 @@ export function useCodeMirror(props: UseCodeMirror) {
110109

111110
useEffect(() => {
112111
if (container && !state) {
113-
const config = {
112+
const stateCurrent = EditorState.create({
114113
doc: value,
115114
selection,
116115
extensions: getExtensions,
117-
};
118-
const stateCurrent = initialState
119-
? EditorState.fromJSON(initialState.json, config, initialState.fields)
120-
: EditorState.create(config);
116+
});
121117
setState(stateCurrent);
122118
if (!view) {
123119
const viewCurrent = new EditorView({

0 commit comments

Comments
 (0)