Skip to content

Commit

Permalink
Fixing a bug that caused theme editing not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Superschnizel committed Jul 21, 2024
1 parent 19a0cbf commit bcc21f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "fast-text-color",
"name": "Fast Text Color",
"version": "1.0.7",
"version": "1.0.71",
"minAppVersion": "0.15.0",
"description": "Quickly apply fully integrated text coloring and formatting with a custom syntax and a keyboard-centric interface.",
"author": "Leon Holtmeier",
Expand Down
26 changes: 17 additions & 9 deletions src/FastTextColorSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ export function getColors(settings: FastTextColorPluginSettings, index: number =
*
* @param {FastTextColorPluginSettings} settings - the plugin settings.
*/
export function getCurrentTheme(settings: FastTextColorPluginSettings) {
return settings.themes[settings.themeIndex];
export function getCurrentTheme(settings: FastTextColorPluginSettings, index: number = -1): TextColorTheme {
if (index == -1) {
index = settings.themeIndex;
}
return settings.themes[index];
}

// THEME functions
Expand Down Expand Up @@ -156,13 +159,13 @@ export class FastTextColorPluginSettingTab extends PluginSettingTab {

newId: string;

themeIndex: number;
editThemeIndex: number;

constructor(app: App, plugin: FastTextColorPlugin) {
super(app, plugin);
this.plugin = plugin;
this.newId = ''
this.themeIndex = plugin.settings.themeIndex;
this.editThemeIndex = plugin.settings.themeIndex;
}


Expand Down Expand Up @@ -194,6 +197,9 @@ export class FastTextColorPluginSettingTab extends PluginSettingTab {
})
})

// ------------------------------------------------------------------
// THEME SETTINGS
// ------------------------------------------------------------------

new Setting(containerEl)
.setName("Edit themes")
Expand All @@ -205,9 +211,9 @@ export class FastTextColorPluginSettingTab extends PluginSettingTab {
dd.addOption(count.toString(), theme.name)
count++;
});
dd.setValue(this.themeIndex.toString())
dd.setValue(this.editThemeIndex.toString())
dd.onChange(value => {
this.themeIndex = +value;
this.editThemeIndex = +value;
this.display();
})
})
Expand Down Expand Up @@ -241,7 +247,7 @@ export class FastTextColorPluginSettingTab extends PluginSettingTab {

// Create Settings for individual Colors.
let count = 1;
getColors(settings, this.themeIndex).forEach((color: TextColor) => {
getColors(settings, this.editThemeIndex).forEach((color: TextColor) => {
this.createColorSetting(themeColorsEl, color, count);
count++;
});
Expand All @@ -259,11 +265,13 @@ export class FastTextColorPluginSettingTab extends PluginSettingTab {
.addButton(btn => {
btn.setButtonText("+")
.onClick(async evt => {
if (getColors(settings).some(tColor => { return tColor.id == this.newId })) {
let colors = getColors(settings, this.editThemeIndex);
if (colors.some(tColor => { return tColor.id == this.newId })) {
new Notice(`color with id ${this.newId} already exists!`);
}

getColors(settings).push(new TextColor("#ffffff", this.newId == '' ? (getColors(settings).length + 1).toString() : this.newId, getCurrentTheme(settings).name));
let newColorName = this.newId == '' ? (colors.length + 1).toString() : this.newId;
colors.push(new TextColor("#ffffff", newColorName , getCurrentTheme(settings, this.editThemeIndex).name));
await this.plugin.saveSettings();
this.display();
})
Expand Down

0 comments on commit bcc21f7

Please sign in to comment.