Fix starting and separators in a row (#7861)

This commit is contained in:
Chris LaFreniere
2019-10-24 15:20:58 -07:00
committed by GitHub
parent 7babd6f3d0
commit a33820ecdd

View File

@@ -57,6 +57,7 @@ export class CellToggleMoreActions {
this._moreActions = new ActionBar(this._moreActionsElement, { orientation: ActionsOrientation.VERTICAL });
this._moreActions.context = { target: this._moreActionsElement };
let validActions = this._actions.filter(a => a instanceof Separator || a instanceof CellActionBase && a.canRun(context));
this.removeDuplicatedAndStartingSeparators(validActions);
this._moreActions.push(this.instantiationService.createInstance(ToggleMoreWidgetAction, validActions, context), { icon: true, label: false });
}
@@ -70,6 +71,25 @@ export class CellToggleMoreActions {
DOM.removeClass(this._moreActionsElement, HIDDEN_CLASS);
}
}
private removeDuplicatedAndStartingSeparators(actions: (Action | CellActionBase)[]): void {
let indexesToRemove: number[] = [];
for (let i = 0; i < actions.length; i++) {
// Never should have a separator at the beginning of the list
if (i === 0 && actions[i] instanceof Separator) {
indexesToRemove.push(0);
}
// Handle multiple separators in a row
if (i > 0 && actions[i] instanceof Separator && actions[i - 1] instanceof Separator) {
indexesToRemove.push(i);
}
}
if (indexesToRemove.length > 0) {
for (let i = indexesToRemove.length - 1; i >= 0; i--) {
actions.splice(indexesToRemove[i], 1);
}
}
}
}
export class AddCellFromContextAction extends CellActionBase {