Skip to content

Commit

Permalink
fix(settings): fixed an issue with changing settings through the sett…
Browse files Browse the repository at this point in the history
…ings page

fix #72
  • Loading branch information
ghaschel committed Nov 11, 2022
1 parent 64186f9 commit 9b46e62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = crlf
end_of_line = lf

[*.md]
max_line_length = off
Expand Down
4 changes: 2 additions & 2 deletions src/ts/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ const activate = function activate(context: vscode.ExtensionContext): void {
const isCustomizationEnabled = config.get('colorCustomizations') as boolean;

if (isCustomizationEnabled) {
updateTokenCustomization();
updateTokenCustomization(true);
} else {
disableTokenCustomization();
disableTokenCustomization(true);
}
}
});
Expand Down
25 changes: 14 additions & 11 deletions src/ts/token-customization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ const removeLegacyColorCustomizations = async (): Promise<SettingsDictionary> =>
return settings;
};

const getOpenTabs = (): string[] =>
vscode.window.tabGroups.all
.map(tabGroup => tabGroup.tabs)
.map(tabs => tabs.map(tab => tab.label))
.flat();
const getOpenTabs = (): string[] => {
const labelList = vscode.window.tabGroups.all.map(tabGroup => tabGroup.tabs).map(tabs => tabs.map(tab => tab.label));

const checkOpenTabs = (openTabs: string[]): boolean =>
openTabs.some(openTab => ['Settings', 'settings.json'].includes(openTab));
return labelList.flat();
};

const checkOpenTabs = (openTabs: string[], fromSettingsChange = false): boolean => {
const labelsList = fromSettingsChange ? ['settings.json'] : ['Settings', 'settings.json'];

return openTabs.some(openTab => labelsList.includes(openTab));
};

const displayTabsMessage = (): void => {
vscode.window.showErrorMessage(
Expand All @@ -86,10 +89,10 @@ const displayTabsMessage = (): void => {
);
};

const disableTokenCustomization = async (): Promise<void> => {
const disableTokenCustomization = async (fromSettingsChange = false): Promise<void> => {
const openTabs = getOpenTabs();

if (checkOpenTabs(openTabs)) {
if (checkOpenTabs(openTabs, fromSettingsChange)) {
displayTabsMessage();

return;
Expand Down Expand Up @@ -125,10 +128,10 @@ const getActiveRulesFromSettings = (configs: vscode.WorkspaceConfiguration): Tex
return rules;
};

const updateTokenCustomization = async (): Promise<void> => {
const updateTokenCustomization = async (fromSettingsChange = false): Promise<void> => {
const openTabs = getOpenTabs();

if (checkOpenTabs(openTabs)) {
if (checkOpenTabs(openTabs, fromSettingsChange)) {
displayTabsMessage();

return;
Expand Down

0 comments on commit 9b46e62

Please sign in to comment.