Skip to content

Commit

Permalink
Fix font reset issue (#107)
Browse files Browse the repository at this point in the history
* fix: force font-picker filter reset when model is reset

* fix type
  • Loading branch information
romgere authored Oct 13, 2023
1 parent 4dc0963 commit d9f109c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/components/ui/font-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ export default class UiFontPicker extends Component<UiFontPickerArgs> {
@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]);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/services/font-manager-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d9f109c

Please sign in to comment.