Remove debounce on key change (#101811)

Fixes: #101466

- Removed debounce, so updates happen in a sync fashion and when the
  user presses tab, it's always moves focus to the correct element.
- An additional check in the `shouldUseSuggestion` reduces the number of
  DOM updates.
This commit is contained in:
Aditya Thakral 2020-07-06 19:38:48 -04:00 committed by GitHub
parent b17c0eca72
commit 62950ee969
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,7 +25,6 @@ import { preferencesEditIcon } from 'vs/workbench/contrib/preferences/browser/pr
import { SelectBox } from 'vs/base/browser/ui/selectBox/selectBox';
import { isIOS } from 'vs/base/common/platform';
import { BrowserFeatures } from 'vs/base/browser/canIUse';
import { debounce } from 'vs/base/common/decorators';
const $ = DOM.$;
export const settingsHeaderForeground = registerColor('settings.headerForeground', { light: '#444444', dark: '#e7e7e7', hc: '#ffffff' }, localize('headerForeground', "The foreground color for a section header or active title."));
@ -781,12 +780,13 @@ export class ObjectSettingWidget extends AbstractListSettingWidget<IObjectDataIt
const changedItem = { ...item };
const onKeyChange = (key: ObjectKey) => {
changedItem.key = key;
this.updateValueUsingSuggestion(key.data, item.value, newValue => {
if (this.shouldUseSuggestion(item.value, changedItem.value, newValue)) {
onValueChange(newValue);
renderLatestValue();
}
});
const suggestedValue = this.valueSuggester(key.data) ?? item.value;
if (this.shouldUseSuggestion(item.value, changedItem.value, suggestedValue)) {
onValueChange(suggestedValue);
renderLatestValue();
}
};
const onValueChange = (value: ObjectValue) => {
changedItem.value = value;
@ -971,14 +971,9 @@ export class ObjectSettingWidget extends AbstractListSettingWidget<IObjectDataIt
return { widget: selectBox, element: wrapper };
}
@debounce(300)
private updateValueUsingSuggestion(key: string, defaultValue: ObjectValue, onUpdate: (value: ObjectValue) => void) {
const suggestion = this.valueSuggester(key);
onUpdate(suggestion ?? defaultValue);
}
private shouldUseSuggestion(originalValue: ObjectValue, previousValue: ObjectValue, newValue: ObjectValue): boolean {
if (previousValue === newValue) {
// suggestion is exactly the same
if (newValue.type !== 'enum' && newValue.type === previousValue.type && newValue.data === previousValue.data) {
return false;
}