Skip to content

Commit

Permalink
Remove debounce on key change (microsoft#101811)
Browse files Browse the repository at this point in the history
Fixes: microsoft#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.
  • Loading branch information
9at8 authored and gjsjohnmurray committed Jul 8, 2020
1 parent d9418a4 commit 3602e80
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts
Expand Up @@ -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."));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3602e80

Please sign in to comment.