Skip to content

Commit

Permalink
fix: duplicating items is not saving and re-rendering toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgurney committed Oct 9, 2024
1 parent c2b0e52 commit 86b68a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Settings/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SettingsManager {
public async addToolbar(toolbar: ToolbarSettings): Promise<void> {
this.plugin.settings.toolbars.push(toolbar);
this.plugin.settings.toolbars.sort((a, b) => a.name.localeCompare(b.name));
await this.plugin.settingsManager.save();
await this.save();
}

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ export class SettingsManager {
* @param item ToolbarItemSettings to duplicate.
* @returns string UUID of the new item.
*/
public duplicateToolbarItem(toolbar: ToolbarSettings, item: ToolbarItemSettings, insertAfter: boolean = false): string {
public async duplicateToolbarItem(toolbar: ToolbarSettings, item: ToolbarItemSettings, insertAfter: boolean = false): Promise<string> {
debugLog('duplicateToolbarItem', item);
let newItem = JSON.parse(JSON.stringify(item)) as ToolbarItemSettings;
newItem.uuid = getUUID();
Expand Down
4 changes: 3 additions & 1 deletion src/Settings/UI/Modals/ToolbarSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ export default class ToolbarSettingsModal extends Modal {
const modifierPressed = (Platform.isWin || Platform.isLinux) ? e?.ctrlKey : e?.metaKey;
if (modifierPressed) {
const newItemUuid = this.plugin.settingsManager.duplicateToolbarItem(this.toolbar, toolbarItem, true);
this.plugin.settingsManager.save();
this.display(`.note-toolbar-sortablejs-list > div[${SettingsAttr.ItemUuid}="${newItemUuid}"] > .note-toolbar-setting-item-preview-container > .note-toolbar-setting-item-preview`);
}
break;
Expand Down Expand Up @@ -683,8 +684,9 @@ export default class ToolbarSettingsModal extends Modal {
button
.setIcon('copy-plus')
.setTooltip(t('setting.item.button-duplicate-tooltip'))
.onClick(() => {
.onClick(async () => {
const newItemUuid = this.plugin.settingsManager.duplicateToolbarItem(this.toolbar, toolbarItem, true);
await this.plugin.settingsManager.save();
this.display(`.note-toolbar-sortablejs-list > div[${SettingsAttr.ItemUuid}="${newItemUuid}"] > .note-toolbar-setting-item-preview-container > .note-toolbar-setting-item-preview`);
});
})
Expand Down

0 comments on commit 86b68a8

Please sign in to comment.