add support for autocomplete delay

This commit is contained in:
Aviral Dasgupta 2017-02-20 19:26:40 +05:30
parent 2d39b25334
commit 32dd89774e
No known key found for this signature in database
GPG key ID: 5FD1E9F4FFD3DA80
4 changed files with 24 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import isEqual from 'lodash/isEqual';
import sdk from '../../../index';
import type {Completion, SelectionRange} from '../../../autocomplete/Autocompleter';
import Q from 'q';
import UserSettingsStore from '../../../UserSettingsStore';
import {getCompletions} from '../../../autocomplete/Autocompleter';
@ -77,9 +78,6 @@ export default class Autocomplete extends React.Component {
}
}
// If no completions were returned, we should turn off force completion.
forceComplete = false;
let hide = this.state.hide;
// These are lists of booleans that indicate whether whether the corresponding provider had a matching pattern
const oldMatches = this.state.completions.map((completion) => !!completion.command.command),
@ -90,6 +88,17 @@ export default class Autocomplete extends React.Component {
hide = false;
}
const autocompleteDelay = UserSettingsStore.getSyncedSetting('autocompleteDelay', 200);
// We had no completions before, but do now, so we should apply our display delay here
if (this.state.completionList.length === 0 && completionList.length > 0 &&
!forceComplete && autocompleteDelay > 0) {
await Q.delay(autocompleteDelay);
}
// Force complete is turned off each time since we can't edit the query in that case
forceComplete = false;
this.setState({
completions,
completionList,