@@ -13,7 +13,10 @@ import { connect } from 'react-redux'
13
13
import onHasCompletion from './onHasCompletion'
14
14
import { editQuery } from '../../state/sessions/actions'
15
15
import { createStructuredSelector } from 'reselect'
16
- import { getQuery } from '../../state/sessions/selectors'
16
+ import {
17
+ getQuery ,
18
+ getSelectedSessionIdFromRoot ,
19
+ } from '../../state/sessions/selectors'
17
20
/**
18
21
* QueryEditor
19
22
*
@@ -38,6 +41,7 @@ export interface ReduxProps {
38
41
showDocForReference ?: ( reference : any ) => void
39
42
onChange ?: ( query : string ) => void
40
43
value : string
44
+ sessionId ?: string
41
45
}
42
46
43
47
const md = new MD ( )
@@ -177,6 +181,12 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
177
181
this . ignoreChangeEvent = false
178
182
}
179
183
184
+ componentWillReceiveProps ( nextProps ) {
185
+ if ( this . props . sessionId !== nextProps . sessionId ) {
186
+ this . closeCompletion ( )
187
+ }
188
+ }
189
+
180
190
componentWillUnmount ( ) {
181
191
this . editor . off ( 'change' , this . onEdit )
182
192
this . editor . off ( 'keyup' , this . onKeyUp )
@@ -209,6 +219,9 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
209
219
210
220
private onKeyUp = ( _ , event ) => {
211
221
const code = event . keyCode
222
+ if ( code === 86 ) {
223
+ return
224
+ }
212
225
if (
213
226
( code >= 65 && code <= 90 ) || // letters
214
227
( ! event . shiftKey && code >= 48 && code <= 57 ) || // numbers
@@ -234,10 +247,20 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
234
247
private onHasCompletion = ( cm , data ) => {
235
248
onHasCompletion ( cm , data , this . props . onHintInformationRender )
236
249
}
250
+
251
+ private closeCompletion = ( ) => {
252
+ if (
253
+ this . editor . state . completionActive &&
254
+ typeof this . editor . state . completionActive . close === 'function'
255
+ ) {
256
+ this . editor . state . completionActive . close ( )
257
+ }
258
+ }
237
259
}
238
260
239
261
const mapStateToProps = createStructuredSelector ( {
240
262
value : getQuery ,
263
+ sessionId : getSelectedSessionIdFromRoot ,
241
264
} )
242
265
243
266
export default connect ( mapStateToProps , { onChange : editQuery } ) ( QueryEditor )
0 commit comments