Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)

Fix anki flashcard format errors on deleting too many (#2167)

* Disallow card format index to be -1

* Fix error on trying to find invalid icon

* Prevent deleting all card formats

authored by

Kuuuube and committed by
GitHub
789ea2fc 56e7350c

+7 -1
+7 -1
ext/js/pages/settings/anki-controller.js
··· 350 350 /** @type {HTMLSelectElement} */ 351 351 const iconSelect = querySelectorNotNull(this._ankiCardPrimary, '.anki-card-icon'); 352 352 iconSelect.dataset.setting = ObjectPropertyAccessor.getPathString(['anki', 'cardFormats', cardFormatIndex, 'icon']); 353 - iconSelect.dataset.icon = this._ankiOptions?.cardFormats[cardFormatIndex].icon ?? 'big-circle'; 353 + iconSelect.dataset.icon = this._ankiOptions?.cardFormats[cardFormatIndex]?.icon ?? 'big-circle'; 354 354 } 355 355 356 356 /** ··· 638 638 if (this._cardFormatIndex > ankiOptions.cardFormats.length) { 639 639 this._cardFormatIndex = ankiOptions.cardFormats.length - 1; 640 640 } 641 + if (this._cardFormatIndex < 0) { 642 + this._cardFormatIndex = 0; 643 + } 641 644 642 645 for (let i = 0; i < ankiOptions.cardFormats.length; ++i) { 643 646 const cardFormat = ankiOptions.cardFormats[i]; ··· 646 649 input.checked = true; 647 650 } 648 651 } 652 + 653 + this._cardFormatDeleteButton.disabled = ankiOptions.cardFormats.length <= 1; 649 654 650 655 this._setCardFormatIndex(this._cardFormatIndex, 'anki-card-term-field-menu'); 651 656 } ··· 721 726 */ 722 727 _onCardFormatDeleteClick(e) { 723 728 e.preventDefault(); 729 + if (this._ankiOptions && this._ankiOptions.cardFormats.length === 1) { return; } 724 730 this.openDeleteCardFormatModal(this._cardFormatIndex); 725 731 } 726 732