Skip to content

Commit

Permalink
Make dict moving faster and save scroll location (#1671)
Browse files Browse the repository at this point in the history
* Make dict moving faster and save scroll location

* Replace dictionaryInfoMap with find

* Replace cleanup loop with map

* Make for loop sane
  • Loading branch information
Kuuuube authored Dec 17, 2024
1 parent 68a5979 commit f3dff02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]} */
Expand Down Expand Up @@ -643,7 +645,7 @@ export class DictionaryController {
const event = {source: this};
this._settingsController.trigger('dictionarySettingsReordered', event);

await this._updateEntries();
this._updateCurrentEntries(options);
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion ext/templates-modals.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>
</div>
<div class="modal-body">
<div id="dictionaries-modal-body" class="modal-body">
<div class="settings-item">
<div class="settings-item-inner">
<div class="settings-item-left">
Expand Down

0 comments on commit f3dff02

Please sign in to comment.