Skip to content

Commit

Permalink
Fix autocompletion. Closes #622, closes #611
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Apr 2, 2018
1 parent 5e6e48c commit 850c1e0
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { connect } from 'react-redux'
import onHasCompletion from './onHasCompletion'
import { editQuery } from '../../state/sessions/actions'
import { createStructuredSelector } from 'reselect'
import { getQuery } from '../../state/sessions/selectors'
import {
getQuery,
getSelectedSessionIdFromRoot,
} from '../../state/sessions/selectors'
/**
* QueryEditor
*
Expand All @@ -38,6 +41,7 @@ export interface ReduxProps {
showDocForReference?: (reference: any) => void
onChange?: (query: string) => void
value: string
sessionId?: string
}

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

componentWillReceiveProps(nextProps) {
if (this.props.sessionId !== nextProps.sessionId) {
this.closeCompletion()
}
}

componentWillUnmount() {
this.editor.off('change', this.onEdit)
this.editor.off('keyup', this.onKeyUp)
Expand Down Expand Up @@ -209,6 +219,9 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {

private onKeyUp = (_, event) => {
const code = event.keyCode
if (code === 86) {

This comment has been minimized.

Copy link
@schickling

schickling Apr 2, 2018

Collaborator

@timsuchanek can you add a comment on what this part does? :)

return
}
if (
(code >= 65 && code <= 90) || // letters
(!event.shiftKey && code >= 48 && code <= 57) || // numbers
Expand All @@ -234,10 +247,20 @@ export class QueryEditor extends React.PureComponent<Props & ReduxProps, {}> {
private onHasCompletion = (cm, data) => {
onHasCompletion(cm, data, this.props.onHintInformationRender)
}

private closeCompletion = () => {
if (
this.editor.state.completionActive &&
typeof this.editor.state.completionActive.close === 'function'
) {
this.editor.state.completionActive.close()
}
}
}

const mapStateToProps = createStructuredSelector({
value: getQuery,
sessionId: getSelectedSessionIdFromRoot,
})

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

0 comments on commit 850c1e0

Please sign in to comment.