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