Skip to content

Commit 850c1e0

Browse files
committed
Fix autocompletion. Closes #622, closes #611
1 parent 5e6e48c commit 850c1e0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/graphql-playground-react/src/components/Playground/QueryEditor.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { connect } from 'react-redux'
1313
import onHasCompletion from './onHasCompletion'
1414
import { editQuery } from '../../state/sessions/actions'
1515
import { createStructuredSelector } from 'reselect'
16-
import { getQuery } from '../../state/sessions/selectors'
16+
import {
17+
getQuery,
18+
getSelectedSessionIdFromRoot,
19+
} from '../../state/sessions/selectors'
1720
/**
1821
* QueryEditor
1922
*
@@ -38,6 +41,7 @@ export interface ReduxProps {
3841
showDocForReference?: (reference: any) => void
3942
onChange?: (query: string) => void
4043
value: string
44+
sessionId?: string
4145
}
4246

4347
const md = new MD()
@@ -177,6 +181,12 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
177181
this.ignoreChangeEvent = false
178182
}
179183

184+
componentWillReceiveProps(nextProps) {
185+
if (this.props.sessionId !== nextProps.sessionId) {
186+
this.closeCompletion()
187+
}
188+
}
189+
180190
componentWillUnmount() {
181191
this.editor.off('change', this.onEdit)
182192
this.editor.off('keyup', this.onKeyUp)
@@ -209,6 +219,9 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
209219

210220
private onKeyUp = (_, event) => {
211221
const code = event.keyCode
222+
if (code === 86) {
223+
return
224+
}
212225
if (
213226
(code >= 65 && code <= 90) || // letters
214227
(!event.shiftKey && code >= 48 && code <= 57) || // numbers
@@ -234,10 +247,20 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
234247
private onHasCompletion = (cm, data) => {
235248
onHasCompletion(cm, data, this.props.onHintInformationRender)
236249
}
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+
}
237259
}
238260

239261
const mapStateToProps = createStructuredSelector({
240262
value: getQuery,
263+
sessionId: getSelectedSessionIdFromRoot,
241264
})
242265

243266
export default connect(mapStateToProps, { onChange: editQuery })(QueryEditor)

0 commit comments

Comments
 (0)