Skip to content

Commit

Permalink
2 bug fixes
Browse files Browse the repository at this point in the history
- Theme settings being deleted if nothing is selected when running `Base16: Activate theme` command
- Duplicate themes appearing in item picker list when running `Base16: Activate theme` command
  • Loading branch information
golf1052 committed Sep 20, 2022
1 parent f3d9f09 commit b58cef7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/extension-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,14 @@ function getThemeNameFromTheme(t: Theme) {

function getThemeNameFromThemePath(path: string) {
// Gets the filename of the relative theme path without .json
// /themes/ is optional
// Group 2 is the filename of the theme without .json
// https://regex101.com/r/d2Ld7K/1
const themeNameRegex = /^(.\/themes\/)(.*?)(\.json)?$/;
// https://regex101.com/r/d2Ld7K/2
const themeNameRegex = /^(.\/themes\/)?(.*?)(\.json)?$/;
return path.replace(themeNameRegex, '$2');
}

export async function promptPickItems(themes: vscode.QuickPickItem[]): Promise<string[]> {
export async function promptPickItems(themes: vscode.QuickPickItem[]): Promise<string[] | null> {
const selectedThemes = await vscode.window.showQuickPick(themes, {
ignoreFocusOut: false,
matchOnDescription: false,
Expand All @@ -229,7 +230,7 @@ export async function promptPickItems(themes: vscode.QuickPickItem[]): Promise<s
});

if (!selectedThemes) {
return [];
return null;
}

return selectedThemes.map((item) => item.description!);
Expand Down
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ async function activateTheme() {
let configThemes = vscode.workspace.getConfiguration().get(ConfigurationPropertyName) as string[];
const themeItems = helpers.getThemeItems(configThemes);
const selectedThemes = await helpers.promptPickItems(themeItems);
if (!selectedThemes) {
return;
}
const compareResult = helpers.compareThemes(selectedThemes, configThemes);

if (compareResult.equal) {
Expand All @@ -46,7 +49,7 @@ async function deactivateTheme() {
const themeItems = helpers.getThemeItemsToDisable(configThemes);
const selectedThemes = await helpers.promptPickItems(themeItems);

if (!selectedThemes.length) {
if (!selectedThemes || selectedThemes.length === 0) {
vscode.window.showInformationMessage('No themes to deactivate.');
return;
}
Expand Down

0 comments on commit b58cef7

Please sign in to comment.