Skip to content

Commit

Permalink
fix: toggle setting should work for arrays (usernamehw#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
usernamehw committed Jun 2, 2022
1 parent 3b470b4 commit 21dd0ac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ConfigurationTarget, window, workspace } from 'vscode';
import { $config } from './extension';
import { ToggleSetting } from './types';
import { isSimpleObject } from './utils';
import isEqual from 'lodash/isEqual';

/**
* Toggle global user setting.
Expand Down Expand Up @@ -79,8 +80,8 @@ export async function updateSetting(settingName: string, newValue: unknown, targ
* Get next item in array. If there is no next - return the first item.
*/
export function getNextOrFirstElement<T>(arr: T[], target: unknown): T {
const idx = arr.findIndex(el => el === target);
return idx === arr.length - 1 ? arr[0] : arr[idx + 1];
const index = arr.findIndex(el => isEqual(el, target));
return index === arr.length - 1 ? arr[0] : arr[index + 1];
}
// commands.registerCommand(`${EXTENSION_NAME}.settingsMerge`, (arg: unknown) => {
// if (!isSimpleObject(arg)) {
Expand Down

0 comments on commit 21dd0ac

Please sign in to comment.