提交 e3277906 编写于 作者: R Rob Lourens

Settings editor - focus tree on TOC selection

上级 d6958430
......@@ -96,7 +96,7 @@ export class SettingsEditor2 extends BaseEditor {
this.inSettingsEditorContextKey = CONTEXT_SETTINGS_EDITOR.bindTo(contextKeyService);
this.searchFocusContextKey = CONTEXT_SETTINGS_SEARCH_FOCUS.bindTo(contextKeyService);
this._register(configurationService.onDidChangeConfiguration(() => this.refreshTreeAndMaintainFocus()));
this._register(configurationService.onDidChangeConfiguration(() => this.onConfigUpdate()));
}
createEditor(parent: HTMLElement): void {
......@@ -241,7 +241,11 @@ export class SettingsEditor2 extends BaseEditor {
this._register(this.tocTree.onDidChangeSelection(e => {
if (this.settingsTreeModel) {
const element = this.settingsTreeModel.getElementById(e.selection[0] && e.selection[0].id);
if (element) {
this.settingsTree.reveal(element, 0);
this.settingsTree.setSelection([element]);
this.settingsTree.setFocus(element);
}
}
}));
}
......@@ -430,9 +434,7 @@ export class SettingsEditor2 extends BaseEditor {
}
this.defaultSettingsEditorModel = model;
this.settingsTreeModel = this.instantiationService.createInstance(SettingsTreeModel, this.viewState, tocData, this.defaultSettingsEditorModel.settingsGroups.slice(1));
this.tocTree.setInput(this.settingsTreeModel.root);
this.settingsTree.setInput(this.settingsTreeModel.root);
this.onConfigUpdate();
});
}
return TPromise.as(null);
......@@ -442,6 +444,17 @@ export class SettingsEditor2 extends BaseEditor {
DOM.toggleClass(this.getContainer(), 'search-mode', !!this.searchResultModel);
}
private onConfigUpdate(): TPromise<void> {
this.settingsTreeModel = this.instantiationService.createInstance(SettingsTreeModel, this.viewState, tocData, this.defaultSettingsEditorModel.settingsGroups.slice(1));
if (!this.searchResultModel) {
this.settingsTree.setInput(this.settingsTreeModel.root);
this.tocTree.setInput(this.settingsTreeModel.root);
}
return this.refreshTreeAndMaintainFocus();
}
private refreshTreeAndMaintainFocus(): TPromise<any> {
// Sort of a hack to maintain focus on the focused control across a refresh
const focusedRowItem = DOM.findParentWithClass(<HTMLElement>document.activeElement, 'setting-item');
......
......@@ -253,17 +253,13 @@ export class SettingsDataSource implements IDataSource {
if (element instanceof SearchResultModel) {
return this.getSearchResultChildren(element);
} else if (element instanceof SettingsTreeGroupElement) {
return this.getGroupChildren(element);
return element.children;
} else {
// No children...
return null;
}
}
private getGroupChildren(groupElement: SettingsTreeGroupElement): SettingsTreeElement[] {
return groupElement.children;
}
getParent(tree: ITree, element: SettingsTreeElement): TPromise<any, any> {
return TPromise.wrap(element.parent);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册