-
Notifications
You must be signed in to change notification settings - Fork 27.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#34685 Collapse search results one level at a time #37451
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -427,7 +427,7 @@ export class CollapseAllAction extends Action { | |
return TPromise.as(null); // Global action disabled if user is in edit mode from another action | ||
} | ||
|
||
this.viewer.collapseAll(); | ||
this.viewer.collapseDeepestExpandedLevel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This action shouldn't be called CollapseAllAction anymore |
||
this.viewer.clearSelection(); | ||
this.viewer.clearFocus(); | ||
this.viewer.DOMFocus(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -486,6 +486,17 @@ export class Item extends Events.EventEmitter { | |
return result; | ||
} | ||
|
||
public getChildren(): Item[] { | ||
var child = this.firstChild; | ||
var results = []; | ||
while (child) { | ||
results.push(child); | ||
child = child.next; | ||
} | ||
|
||
return results; | ||
} | ||
|
||
private isAncestorOf(item: Item): boolean { | ||
while (item) { | ||
if (item.id === this.id) { | ||
|
@@ -882,18 +893,29 @@ export class TreeModel extends Events.EventEmitter { | |
return item.collapse(recursive); | ||
} | ||
|
||
public collapseAll(elements: any[] = null, recursive: boolean = false): WinJS.Promise { | ||
if (!elements) { | ||
elements = [this.input]; | ||
recursive = true; | ||
} | ||
var promises = []; | ||
for (var i = 0, len = elements.length; i < len; i++) { | ||
promises.push(this.collapse(elements[i], recursive)); | ||
public collapseDeepestExpandedLevel(): WinJS.Promise { | ||
var levelToCollapse = this.findDeepestExpandedLevel(this.input, 0); | ||
|
||
var items = [this.input]; | ||
for (var i = 0; i < levelToCollapse; i++) { | ||
items = items | ||
.map(node => node.getChildren()) | ||
.reduce((prev, current) => prev.concat(current), []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a helper for this, |
||
} | ||
|
||
var promises = items.map(child => this.collapse(child, false)); | ||
return WinJS.Promise.join(promises); | ||
} | ||
|
||
private findDeepestExpandedLevel(item: Item, currentLevel: number): number { | ||
var expandedChildren = item.getChildren().filter(child => child.isExpanded()); | ||
if (!expandedChildren.length) { | ||
return currentLevel; | ||
} | ||
|
||
return Math.max(...expandedChildren.map(child => this.findDeepestExpandedLevel(child, currentLevel + 1))); | ||
} | ||
|
||
public toggleExpansion(element: any, recursive: boolean = false): WinJS.Promise { | ||
return this.isExpanded(element) ? this.collapse(element, recursive) : this.expand(element); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,12 +259,12 @@ export class ToggleViewletAction extends Action { | |
export class CollapseAction extends Action { | ||
|
||
constructor(viewer: ITree, enabled: boolean, clazz: string) { | ||
super('workbench.action.collapse', nls.localize('collapse', "Collapse All"), clazz, enabled, (context: any) => { | ||
super('workbench.action.collapse', nls.localize('collapse', "Collapse"), clazz, enabled, (context: any) => { | ||
if (viewer.getHighlight()) { | ||
return TPromise.as(null); // Global action disabled if user is in edit mode from another action | ||
} | ||
|
||
viewer.collapseAll(); | ||
viewer.collapseDeepestExpandedLevel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have two actions that do the same thing. Let's replace one with an action that calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've scoped it to just search results for now |
||
viewer.clearSelection(); | ||
viewer.clearFocus(); | ||
viewer.DOMFocus(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave
collapseAll
in place, havingcollapseDeepestExpandedLevel
as a new method