未验证 提交 62950ee9 编写于 作者: A Aditya Thakral 提交者: GitHub

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.
上级 b17c0eca
......@@ -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);
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册