mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 23:15:29 +02:00
Refactor ZenWorkspaces shortcutSwitchTo method to handle out of bounds index gracefully
This commit is contained in:
parent
c65b4aef13
commit
53b7f6eecc
2 changed files with 296 additions and 196 deletions
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue