Skip to content

Commit

Permalink
Address KM comments
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
  • Loading branch information
Colin Grant committed May 12, 2021
1 parent ec60db2 commit 76e1cb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
17 changes: 15 additions & 2 deletions packages/preferences/src/browser/preference-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ export class PreferenceTreeModel extends TreeModelImpl {
this.updateFilteredRows(PreferenceFilterChangeSource.Scope);
}),
this.filterInput.onFilterChanged(newSearchTerm => {
const wasFiltered = this._isFiltered;
this.lastSearchedLiteral = newSearchTerm;
this.lastSearchedFuzzy = newSearchTerm.replace(/\s/g, '');
this._isFiltered = newSearchTerm.length > 2;
this.updateFilteredRows(PreferenceFilterChangeSource.Search);
if (!wasFiltered && this.isFiltered) {
this.expandAll();
}
}),
this.onFilterChanged(() => {
this.filterInput.updateResultsCount(this._totalVisibleLeaves);
Expand Down Expand Up @@ -202,15 +206,24 @@ export class PreferenceTreeModel extends TreeModelImpl {
this.expandNode(openNode);
}
if (CompositeTreeNode.is(this.root)) {
const { children } = this.root;
children.forEach(child => {
this.root.children.forEach(child => {
if (child !== openNode && ExpandableTreeNode.is(child)) {
this.collapseNode(child);
}
});
}
}

protected expandAll(): void {
if (CompositeTreeNode.is(this.root)) {
this.root.children.forEach(child => {
if (ExpandableTreeNode.is(child)) {
this.expandNode(child);
}
});
}
}

/**
* @returns true if selection changed, false otherwise
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
import { postConstruct, injectable, inject } from '@theia/core/shared/inversify';
import debounce = require('@theia/core/shared/lodash.debounce');
import throttle = require('@theia/core/shared/lodash.throttle');
import {
PreferenceService,
CompositeTreeNode,
Expand Down Expand Up @@ -101,7 +101,7 @@ export class PreferencesEditorWidget extends BaseWidget implements StatefulWidge
} else {
((otherSource: never) => { throw new Error('You should handle all possible sources of change!'); })(e.source);
}
this.resetScroll(currentFirstVisible, !isFiltered);
this.resetScroll(currentFirstVisible, e.source === PreferenceFilterChangeSource.Search && !isFiltered);
}

protected handleSchemaChange(isFiltered: boolean): void {
Expand Down Expand Up @@ -180,7 +180,7 @@ export class PreferencesEditorWidget extends BaseWidget implements StatefulWidge
*/
protected hideIfFailsFilters(renderer: GeneralPreferenceNodeRenderer, isFiltered: boolean): boolean {
const row = this.model.currentRows.get(renderer.nodeId);
if (!row || (isFiltered && CompositeTreeNode.is(row.node))) {
if (!row || (CompositeTreeNode.is(row.node) && (isFiltered || row.visibleChildren === 0))) {
renderer.hide();
return true;
} else {
Expand Down Expand Up @@ -210,10 +210,10 @@ export class PreferencesEditorWidget extends BaseWidget implements StatefulWidge
const renderer = collection.get(id);
if (renderer?.visible) {
renderer.node.scrollIntoView();
return;
}
} else {
this.scrollContainer.scrollTop = 0;
}
this.scrollContainer.scrollTop = 0;
});
};

Expand All @@ -230,7 +230,7 @@ export class PreferencesEditorWidget extends BaseWidget implements StatefulWidge
}
};

onScroll = debounce(this.doOnScroll.bind(this), 50, { leading: false, trailing: true });
onScroll = throttle(this.doOnScroll.bind(this), 50);

protected findFirstVisibleChildID(): string | undefined {
const { scrollTop } = this.scrollContainer;
Expand Down Expand Up @@ -261,7 +261,7 @@ export class PreferencesEditorWidget extends BaseWidget implements StatefulWidge
this.currentModelSelectionId = selectionAncestor.id;
expansionAncestor = expansionAncestor ?? selectionAncestor;
this.model.selectIfNotSelected(selectionAncestor);
if (id !== this.lastUserSelection) {
if (!this.model.isFiltered && id !== this.lastUserSelection) {
this.lastUserSelection = '';
this.model.collapseAllExcept(expansionAncestor);
}
Expand All @@ -279,6 +279,8 @@ export class PreferencesEditorWidget extends BaseWidget implements StatefulWidge
const { id, collection } = this.analyzeIDAndGetRendererGroup(candidate.id);
const renderer = collection.get(id);
if (renderer?.visible) {
// When filtered, treat the first visible child as the selected node, since it will be the one scrolled to.
this.lastUserSelection = renderer.nodeId;
renderer.node.scrollIntoView();
return;
}
Expand Down

0 comments on commit 76e1cb1

Please sign in to comment.