@@ -25,18 +25,16 @@ const databaseTypeList = Object.keys(DatabaseTypeCode).map((d) => ({
2525
2626interface IProps {
2727 id : string ;
28- isActive ?: boolean ;
28+ conceal ?: boolean ;
2929 language ?: string ;
3030 className ?: string ;
3131 options ?: IEditorOptions ;
3232 needDestroy ?: boolean ;
3333 addAction ?: Array < { id : string ; label : string ; action : ( selectedText : string , ext ?: string ) => void } > ;
3434 defaultValue ?: string ;
3535 appendValue ?: IAppendValue ;
36- // onChange?: (v: string, e?: IEditorContentChangeEvent) => void;
3736 didMount ?: ( editor : IEditorIns ) => any ;
38- onSave ?: ( value : string ) => void ; // 快捷键保存的回调
39- onExecute ?: ( value : string ) => void ; // 快捷键执行的回调
37+ shortcutKey ?: ( editor , monaco ) => void ;
4038}
4139
4240export interface IExportRefFunction {
@@ -47,18 +45,7 @@ export interface IExportRefFunction {
4745}
4846
4947function MonacoEditor ( props : IProps , ref : ForwardedRef < IExportRefFunction > ) {
50- const {
51- id,
52- className,
53- language = 'sql' ,
54- didMount,
55- options,
56- isActive,
57- onSave,
58- onExecute,
59- defaultValue,
60- appendValue,
61- } = props ;
48+ const { id, className, language = 'sql' , didMount, options, conceal, defaultValue, appendValue, shortcutKey } = props ;
6249 const editorRef = useRef < IEditorIns > ( ) ;
6350 const quickInputCommand = useRef < any > ( ) ;
6451 const [ appTheme ] = useTheme ( ) ;
@@ -112,29 +99,13 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
11299 } , [ ] ) ;
113100
114101 useEffect ( ( ) => {
115- if ( isActive && editorRef . current ) {
116- // 自定义快捷键
117- editorRef . current . addCommand ( monaco . KeyMod . CtrlCmd | monaco . KeyCode . KeyS , ( ) => {
118- const value = editorRef . current ?. getValue ( ) ;
119- onSave ?.( value || '' ) ;
120- } ) ;
121-
122- editorRef . current . addCommand ( monaco . KeyMod . CtrlCmd | monaco . KeyCode . KeyR , ( ) => {
123- const value = getCurrentSelectContent ( ) ;
124- onExecute ?.( value ) ;
125- } ) ;
126-
127- editorRef . current . addCommand ( monaco . KeyMod . CtrlCmd | monaco . KeyCode . KeyR , ( ) => {
128- const value = getCurrentSelectContent ( ) ;
129- onExecute ?.( value ) ;
130- } ) ;
131-
132- // 注册快捷键command+shift+L新建console
133- editorRef . current . addCommand ( monaco . KeyMod . CtrlCmd | monaco . KeyMod . Shift | monaco . KeyCode . KeyL , ( ) => {
134- // onShortcutKeyCallback?.(new KeyboardEvent('keydown', { ctrlKey: true, shiftKey: true, keyCode: 76 }));
135- } ) ;
102+ if ( editorRef . current ) {
103+ // eg:
104+ // editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyL, () => {
105+ // });
106+ shortcutKey ?.( editorRef . current , monaco ) ;
136107 }
137- } , [ editorRef . current , isActive ] ) ;
108+ } , [ editorRef . current ] ) ;
138109
139110 useEffect ( ( ) => {
140111 // 监听浏览器窗口大小变化,重新渲染编辑器
@@ -235,6 +206,8 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
235206 return < div ref = { ref as any } id = { `monaco-editor-${ id } ` } className = { cs ( className , styles . editorContainer ) } /> ;
236207}
237208
209+ // , { [styles.concealEditor]: conceal }
210+
238211// text 需要添加的文本
239212// range 添加到的位置
240213// 'end' 末尾
0 commit comments