From d9f109c4f87aa97775ff4c14f238c8c0c79cf59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Mestres?= Date: Fri, 13 Oct 2023 14:38:15 +0200 Subject: [PATCH] Fix font reset issue (#107) * fix: force font-picker filter reset when model is reset * fix type --- app/components/ui/font-picker.ts | 12 ++++++++++++ tests/unit/services/font-manager-test.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/components/ui/font-picker.ts b/app/components/ui/font-picker.ts index e15cf01..0935ca3 100644 --- a/app/components/ui/font-picker.ts +++ b/app/components/ui/font-picker.ts @@ -62,6 +62,18 @@ export default class UiFontPicker extends Component { @action onFontNameChange(e: CustomEvent) { const fontName = (e.target as CalciteCombobox).value as string; + // This is not supposed to happen (aka. not initiate by "calcite-combobox") + // this happens when `fontName` change from outside of font-picker & actual filter are no longer returning a list containing `fontName` + if (!fontName) { + // Reset font-picker to current font + const currentFont = this.fontManager.fontList.get(this.args.fontName); + if (currentFont) { + this.fontCategory = currentFont.category; + this.fontScript = undefined; + return; + } + } + const font = this.fontManager.fontList.get(fontName); if (font) { this.args.onFontSettingsChange(fontName, font.variants[0]); diff --git a/tests/unit/services/font-manager-test.ts b/tests/unit/services/font-manager-test.ts index f0b1a55..77e6c69 100644 --- a/tests/unit/services/font-manager-test.ts +++ b/tests/unit/services/font-manager-test.ts @@ -3,7 +3,7 @@ import { setupTest } from 'ember-qunit'; import * as opentype from 'opentype.js'; import cases from 'qunit-parameterize'; import type FontManagerService from 'text2stl/services/font-manager'; -import type { Variant } from '@samuelmeuli/font-manager'; +import type { Variant } from 'text2stl/services/font-manager'; const mockedFontList = new Map();