Skip to content

Commit

Permalink
Make dict moving faster and save scroll location
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Dec 16, 2024
1 parent 67a509c commit 16ace1a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 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,36 @@ export class DictionaryController {
}
}

/**
* @param {import('settings').ProfileOptions} options
*/
_updateCurrentEntries(options) {
const dictionariesModalBodyScrollY = this._dictionaryModalBody.scrollTop;
const dictionaries = this._dictionaries;
if (dictionaries === null) { return; }

for (const entry of this._dictionaryEntries) {
entry.cleanup();
}

/** @type {Map<string, import('dictionary-importer').Summary>} */
const dictionaryInfoMap = new Map();
for (const dictionary of dictionaries) {
dictionaryInfoMap.set(dictionary.title, dictionary);
}

const dictionaryOptionsArray = options.dictionaries;
for (let i = 0, ii = dictionaryOptionsArray.length; i < ii; ++i) {
const {name} = dictionaryOptionsArray[i];
/** @type {import('dictionary-importer').Summary | undefined} */
const dictionaryInfo = dictionaryInfoMap.get(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 16ace1a

Please sign in to comment.