1
1
import { useEffect , useState } from 'react' ;
2
- import { basicSetup } from '@codemirror/basic-setup' ;
2
+ import { basicSetup as defaultBasicSetup } from '@codemirror/basic-setup' ;
3
3
import { EditorState , StateEffect } from '@codemirror/state' ;
4
- import { indentWithTab } from '@codemirror/commands' ;
4
+ import { indentWithTab as defaultIndentWithTab } from '@codemirror/commands' ;
5
5
import { EditorView , keymap , ViewUpdate } from '@codemirror/view' ;
6
6
import { ReactCodeMirrorProps } from './' ;
7
7
import { oneDarkTheme } from '@codemirror/theme-one-dark' ;
@@ -26,6 +26,8 @@ export function useCodeMirror(props: UseCodeMirror) {
26
26
width = '' ,
27
27
minWidth = '' ,
28
28
maxWidth = '' ,
29
+ indentWithTab = true ,
30
+ basicSetup = true ,
29
31
} = props ;
30
32
const [ container , setContainer ] = useState ( props . container ) ;
31
33
const [ view , setView ] = useState < EditorView > ( ) ;
@@ -47,7 +49,13 @@ export function useCodeMirror(props: UseCodeMirror) {
47
49
onChange ( value , vu ) ;
48
50
}
49
51
} ) ;
50
- let getExtensions = [ basicSetup , keymap . of ( [ indentWithTab ] ) , updateListener , defaultThemeOption ] ;
52
+ let getExtensions = [ updateListener , defaultThemeOption ] ;
53
+ if ( indentWithTab ) {
54
+ getExtensions . unshift ( keymap . of ( [ defaultIndentWithTab ] ) ) ;
55
+ }
56
+ if ( basicSetup ) {
57
+ getExtensions . unshift ( defaultBasicSetup ) ;
58
+ }
51
59
theme === 'light' ? getExtensions . push ( defaultLightThemeOption ) : getExtensions . push ( oneDarkTheme ) ;
52
60
if ( onUpdate && typeof onUpdate === 'function' ) {
53
61
getExtensions . push ( EditorView . updateListener . of ( onUpdate ) ) ;
0 commit comments