Skip to content

Commit 21d77c3

Browse files
authored
feat: expose 'root' config of EditorView (#204)
1 parent e73519d commit 21d77c3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export interface ReactCodeMirrorProps
5454
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
5555
*/
5656
extensions?: Extension[];
57+
/**
58+
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
59+
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
60+
*/
61+
root?: ShadowRoot | Document;
5762
}
5863

5964
export interface ReactCodeMirrorRef {
@@ -82,11 +87,13 @@ const ReactCodeMirror = React.forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProp
8287
placeholder,
8388
indentWithTab,
8489
editable,
90+
root,
8591
...other
8692
} = props;
8793
const editor = useRef<HTMLDivElement>(null);
8894
const { state, view, container, setContainer } = useCodeMirror({
8995
container: editor.current,
96+
root,
9097
value,
9198
autoFocus,
9299
theme,

src/useCodeMirror.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function useCodeMirror(props: UseCodeMirror) {
3030
editable = true,
3131
indentWithTab = true,
3232
basicSetup = true,
33+
root,
3334
} = props;
3435
const [container, setContainer] = useState(props.container);
3536
const [view, setView] = useState<EditorView>();
@@ -86,6 +87,7 @@ export function useCodeMirror(props: UseCodeMirror) {
8687
const viewCurrent = new EditorView({
8788
state: stateCurrent,
8889
parent: container as any,
90+
root,
8991
});
9092
setView(viewCurrent);
9193
}

0 commit comments

Comments
 (0)