@@ -26,6 +26,7 @@ import {
26
26
import { KeyboardShortcut } from 'uiSrc/components'
27
27
import { ThemeContext } from 'uiSrc/contexts/themeContext'
28
28
import { appRedisCommandsSelector } from 'uiSrc/slices/app/redis-commands'
29
+ import { IEditorMount , ISnippetController } from 'uiSrc/pages/workbench/interfaces'
29
30
30
31
import styles from './styles.module.scss'
31
32
@@ -38,15 +39,11 @@ export interface Props {
38
39
onKeyDown ?: ( e : React . KeyboardEvent , script : string ) => void ;
39
40
}
40
41
41
- interface IEditorMount {
42
- editor : monacoEditor . editor . IStandaloneCodeEditor
43
- monaco : typeof monacoEditor
44
- }
45
-
46
42
let decorations : string [ ] = [ ]
47
43
48
44
const Query = ( props : Props ) => {
49
45
const { query = '' , setQuery, onKeyDown, onSubmit, setQueryEl } = props
46
+ let contribution : Nullable < ISnippetController > = null
50
47
51
48
const {
52
49
commandsArray : REDIS_COMMANDS_ARRAY ,
@@ -60,6 +57,7 @@ const Query = (props: Props) => {
60
57
useEffect ( ( ) =>
61
58
// componentWillUnmount
62
59
( ) => {
60
+ contribution ?. dispose ?.( )
63
61
disposeCompletionItemProvider ( )
64
62
disposeSignatureHelpProvider ( )
65
63
} ,
@@ -124,6 +122,21 @@ const Query = (props: Props) => {
124
122
) {
125
123
onTriggerParameterHints ( )
126
124
}
125
+
126
+ if ( e . keyCode === monaco . KeyCode . Enter || e . keyCode === monaco . KeyCode . Space ) {
127
+ onExitSnippetMode ( )
128
+ }
129
+ }
130
+
131
+ const onExitSnippetMode = ( ) => {
132
+ if ( ! monacoObjects . current ) return
133
+ const { editor } = monacoObjects ?. current
134
+
135
+ if ( contribution ?. isInSnippet ?.( ) ) {
136
+ const { lineNumber = 0 , column = 0 } = editor ?. getPosition ( ) ?? { }
137
+ editor . setSelection ( new monaco . Selection ( lineNumber , column , lineNumber , column ) )
138
+ contribution ?. cancel ?.( )
139
+ }
127
140
}
128
141
129
142
const editorDidMount = (
@@ -132,6 +145,10 @@ const Query = (props: Props) => {
132
145
) => {
133
146
monacoObjects . current = { editor, monaco }
134
147
148
+ // hack for exit from snippet mode after click Enter until no answer from monaco authors
149
+ // https://github.com/microsoft/monaco-editor/issues/2756
150
+ contribution = editor . getContribution < ISnippetController > ( 'snippetController2' )
151
+
135
152
editor . focus ( )
136
153
setQueryEl ( editor )
137
154
@@ -179,11 +196,6 @@ const Query = (props: Props) => {
179
196
showIcons : false ,
180
197
} ,
181
198
lineNumbersMinChars : 4
182
- // fontFamily: 'Inconsolata',
183
- // fontSize: 16,
184
- // minimap: {
185
- // enabled: false,
186
- // },
187
199
}
188
200
189
201
return (
0 commit comments