Skip to content
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

fix https://github.com/microsoft/vscode/issues/193957 #193960

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/base/common/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {
/**
* Remove all falsy values from `array`. The original array IS modified.
*/
export function coalesceInPlace<T>(array: Array<T | undefined | null>): void {
export function coalesceInPlace<T>(array: Array<T | undefined | null>): asserts array is Array<T> {
let to = 0;
for (let i = 0; i < array.length; i++) {
if (!!array[i]) {
Expand Down
11 changes: 6 additions & 5 deletions src/vs/platform/actions/browser/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ export class WorkbenchToolBar extends ToolBar {
override setActions(_primary: readonly IAction[], _secondary: readonly IAction[] = [], menuIds?: readonly MenuId[]): void {

this._sessionDisposables.clear();
const primary = _primary.slice();
const primary: Array<IAction | undefined> = _primary.slice(); // for hiding and overflow we set some items to undefined
const secondary = _secondary.slice();
const toggleActions: IAction[] = [];
let toggleActionsCheckedCount: number = 0;

const extraSecondary: IAction[] = [];
const extraSecondary: Array<IAction | undefined> = [];

let someAreHidden = false;
// unless disabled, move all hidden items to secondary group or ignore them
Expand All @@ -145,7 +145,7 @@ export class WorkbenchToolBar extends ToolBar {
// hidden items move into overflow or ignore
if (action.hideActions.isHidden) {
someAreHidden = true;
primary[i] = undefined!;
primary[i] = undefined;
if (this._options?.hiddenItemStrategy !== HiddenItemStrategy.Ignore) {
extraSecondary[i] = action;
}
Expand All @@ -156,7 +156,7 @@ export class WorkbenchToolBar extends ToolBar {
// count for max
if (this._options?.overflowBehavior !== undefined) {

const exemptedIds = intersection(new Set(this._options.overflowBehavior.exempted), Iterable.map(primary, a => a.id));
const exemptedIds = intersection(new Set(this._options.overflowBehavior.exempted), Iterable.map(primary, a => a?.id));
const maxItems = this._options.overflowBehavior.maxItems - exemptedIds.size;

let count = 0;
Expand All @@ -170,12 +170,13 @@ export class WorkbenchToolBar extends ToolBar {
continue;
}
if (count >= maxItems) {
primary[i] = undefined!;
primary[i] = undefined;
extraSecondary[i] = action;
}
}
}

// coalesce turns Array<IAction|undefined> into IAction[]
coalesceInPlace(primary);
coalesceInPlace(extraSecondary);
super.setActions(primary, Separator.join(extraSecondary, secondary));
Expand Down