From f3dff029de9c11878693e3f1f708487f5edaf991 Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:45:24 -0500 Subject: [PATCH 1/4] Make dict moving faster and save scroll location (#1671) * Make dict moving faster and save scroll location * Replace dictionaryInfoMap with find * Replace cleanup loop with map * Make for loop sane --- .../pages/settings/dictionary-controller.js | 26 ++++++++++++++++++- ext/templates-modals.html | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index e2fcf1e32..662de87a5 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -494,6 +494,8 @@ export class DictionaryController { this._settingsController = settingsController; /** @type {import('./modal-controller.js').ModalController} */ this._modalController = modalController; + /** @type {HTMLElement} */ + this._dictionaryModalBody = querySelectorNotNull(document, '#dictionaries-modal-body'); /** @type {import('./status-footer.js').StatusFooter} */ this._statusFooter = statusFooter; /** @type {?import('dictionary-importer').Summary[]} */ @@ -643,7 +645,7 @@ export class DictionaryController { const event = {source: this}; this._settingsController.trigger('dictionarySettingsReordered', event); - await this._updateEntries(); + this._updateCurrentEntries(options); } /** @@ -822,6 +824,28 @@ export class DictionaryController { } } + /** + * @param {import('settings').ProfileOptions} options + */ + _updateCurrentEntries(options) { + const dictionariesModalBodyScrollY = this._dictionaryModalBody.scrollTop; + const dictionaries = this._dictionaries; + if (dictionaries === null) { return; } + + this._dictionaryEntries.map((dictionaryEntry) => dictionaryEntry.cleanup()); + + const dictionaryOptionsArray = options.dictionaries; + for (let i = 0; i < dictionaryOptionsArray.length; i++) { + const {name} = dictionaryOptionsArray[i]; + /** @type {import('dictionary-importer').Summary | undefined} */ + const dictionaryInfo = dictionaries.find((dictionary) => dictionary.title === name); + if (typeof dictionaryInfo === 'undefined') { continue; } + const updateDownloadUrl = dictionaryInfo.downloadUrl ?? null; + this._createDictionaryEntry(i, dictionaryInfo, updateDownloadUrl); + } + this._dictionaryModalBody.scroll({top: dictionariesModalBodyScrollY}); + } + /** * @param {import('settings').ProfileOptions} options */ diff --git a/ext/templates-modals.html b/ext/templates-modals.html index e7c00e55b..48c599551 100644 --- a/ext/templates-modals.html +++ b/ext/templates-modals.html @@ -11,7 +11,7 @@ -