Refactor ZenWorkspaces shortcutSwitchTo method to handle out of bounds index gracefully

This commit is contained in:
mauro-balades 2024-09-24 16:47:42 +02:00
parent c65b4aef13
commit 53b7f6eecc
2 changed files with 296 additions and 196 deletions

View file

@ -832,8 +832,11 @@ var ZenWorkspaces = {
async shortcutSwitchTo(index) {
const workspaces = await this._workspaces();
// The index may be out of bounds, so we need to wrap it around
const workspaceToSwitch = workspaces.workspaces[(index + workspaces.workspaces.length) % workspaces.workspaces.length];
// The index may be out of bounds, if it doesnt exist, don't do anything
if (index >= workspaces.workspaces.length || index < 0) {
return;
}
const workspaceToSwitch = workspaces.workspaces[index];
await this.changeWorkspace(workspaceToSwitch);
}
};