add support for autocomplete delay

pull/21833/head
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

@ -139,7 +139,7 @@ module.exports = {
getSyncedSetting: function(type, defaultValue = null) {
var settings = this.getSyncedSettings();
return settings.hasOwnProperty(type) ? settings[type] : null;
return settings.hasOwnProperty(type) ? settings[type] : defaultValue;
},
setSyncedSetting: function(type, value) {
@ -156,7 +156,7 @@ module.exports = {
getLocalSetting: function(type, defaultValue = null) {
var settings = this.getLocalSettings();
return settings.hasOwnProperty(type) ? settings[type] : null;
return settings.hasOwnProperty(type) ? settings[type] : defaultValue;
},
setLocalSetting: function(type, value) {

View File

@ -43,7 +43,7 @@ export async function getCompletions(query: string, selection: SelectionRange, f
PROVIDERS.map(provider => {
return Q(provider.getCompletions(query, selection, force))
.timeout(PROVIDER_COMPLETION_TIMEOUT);
})
}),
);
return completionsList

View File

@ -508,6 +508,15 @@ module.exports = React.createClass({
{ this._renderUrlPreviewSelector() }
{ SETTINGS_LABELS.map( this._renderSyncedSetting ) }
{ THEMES.map( this._renderThemeSelector ) }
<table>
<tbody>
<tr>
<td><strong>Autocomplete Delay (ms): </strong></td>
<td><input type="number" defaultValue={UserSettingsStore.getLocalSetting('autocompleteDelay', 200)}
onChange={(e) => UserSettingsStore.setLocalSetting('autocompleteDelay', +e.target.value)} /> </td>
</tr>
</tbody>
</table>
</div>
</div>
);

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,