Skip to content

Commit

Permalink
feat: add onCreateEditor props. (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 8, 2022
1 parent 02637ab commit 00b3ce7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ export interface ReactCodeMirrorProps
onChange?(value: string, viewUpdate: ViewUpdate): void;
/** Some data on the statistics editor. */
onStatistics?(data: Statistics): void;
/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
onUpdate?(viewUpdate: ViewUpdate): void;
/**
Expand Down
4 changes: 4 additions & 0 deletions core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface ReactCodeMirrorProps
onStatistics?(data: Statistics): void;
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
onUpdate?(viewUpdate: ViewUpdate): void;
/** The first time the editor executes the event. */
onCreateEditor?(view: EditorView, state: EditorState): void;
/**
* Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.
* They can either be built-in extension-providing objects,
Expand Down Expand Up @@ -83,6 +85,7 @@ const ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((pr
extensions = [],
onChange,
onStatistics,
onCreateEditor,
onUpdate,
autoFocus,
theme = 'light',
Expand Down Expand Up @@ -121,6 +124,7 @@ const ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((pr
selection,
onChange,
onStatistics,
onCreateEditor,
onUpdate,
extensions,
});
Expand Down
2 changes: 2 additions & 0 deletions core/src/useCodeMirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function useCodeMirror(props: UseCodeMirror) {
selection,
onChange,
onStatistics,
onCreateEditor,
onUpdate,
extensions = [],
autoFocus,
Expand Down Expand Up @@ -121,6 +122,7 @@ export function useCodeMirror(props: UseCodeMirror) {
root,
});
setView(viewCurrent);
onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);
}
}
return () => {
Expand Down

0 comments on commit 00b3ce7

Please sign in to comment.