diff --git a/packages/project-editor/features/font/font.tsx b/packages/project-editor/features/font/font.tsx index c1f7b3394..485b284b0 100644 --- a/packages/project-editor/features/font/font.tsx +++ b/packages/project-editor/features/font/font.tsx @@ -1585,7 +1585,36 @@ export class Font extends EezObject { return undefined; } }, - icon: "material:font_download" + icon: "material:font_download", + + updateObjectValueHook: (font: Font, values: Partial) => { + const projectStore = getProjectStore(font); + if ( + projectStore.projectTypeTraits.isLVGL && + values.name != undefined && + font.name != values.name + ) { + projectStore.undoManager.postponeSetCombineCommandsFalse = true; + + setTimeout(async () => { + projectStore.undoManager.postponeSetCombineCommandsFalse = + false; + + try { + await font.rebuildLvglFont( + projectStore, + projectStore.project.settings.general.lvglVersion, + projectStore.project.settings.build.lvglInclude, + values.name + ); + } catch (err) { + console.error(err); + } + + projectStore.undoManager.setCombineCommands(false); + }); + } + } }; get glyphsMap() { @@ -1682,14 +1711,15 @@ export class Font extends EezObject { async rebuildLvglFont( projectStore: ProjectStore, lvglVersion: string, - lvglInclude: string + lvglInclude: string, + name?: string ) { if (!this.embeddedFontFile) { return; } const fontProperties = await extractFont({ - name: this.name, + name: name || this.name, absoluteFilePath: projectStore.getAbsoluteFilePath( this.source!.filePath ), diff --git a/packages/project-editor/store/undo-manager.ts b/packages/project-editor/store/undo-manager.ts index f624088ad..5f76a9e24 100644 --- a/packages/project-editor/store/undo-manager.ts +++ b/packages/project-editor/store/undo-manager.ts @@ -19,6 +19,8 @@ export class UndoManager { private selectionBeforeFirstCommand: any; public combineCommands: boolean = false; + postponeSetCombineCommandsFalse: boolean = false; + constructor(public projectStore: ProjectStore) { makeObservable(this, { undoStack: observable, @@ -61,6 +63,10 @@ export class UndoManager { } setCombineCommands(value: boolean) { + if (value == false && this.postponeSetCombineCommandsFalse) { + return; + } + this.pushToUndoStack(); this.combineCommands = value;