Improve the behaviour of the "Move to..." action (#1667)

This commit is contained in:
toasted-nutbread 2021-05-11 18:11:10 -04:00 committed by GitHub
parent de57d73826
commit e7d349c3ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,7 +169,7 @@ class DictionaryEntry {
} }
_move(offset) { _move(offset) {
this._dictionaryController.swapDictionaryOptions(this._index, this._index + offset); this._dictionaryController.moveDictionaryOptions(this._index, this._index + offset);
} }
_setMenuActionEnabled(menu, action, enabled) { _setMenuActionEnabled(menu, action, enabled) {
@ -305,21 +305,24 @@ class DictionaryController {
modal.setVisible(true); modal.setVisible(true);
} }
async swapDictionaryOptions(index1, index2) { async moveDictionaryOptions(currentIndex, targetIndex) {
const options = await this._settingsController.getOptions(); const options = await this._settingsController.getOptions();
const {dictionaries} = options; const {dictionaries} = options;
if ( if (
index1 < 0 || index1 >= dictionaries.length || currentIndex < 0 || currentIndex >= dictionaries.length ||
index2 < 0 || index2 >= dictionaries.length || targetIndex < 0 || targetIndex >= dictionaries.length ||
index1 === index2 currentIndex === targetIndex
) { ) {
return; return;
} }
const item = dictionaries.splice(currentIndex, 1)[0];
dictionaries.splice(targetIndex, 0, item);
await this._settingsController.modifyProfileSettings([{ await this._settingsController.modifyProfileSettings([{
action: 'swap', action: 'set',
path1: `dictionaries[${index1}]`, path: 'dictionaries',
path2: `dictionaries[${index2}]` value: dictionaries
}]); }]);
await this._updateEntries(); await this._updateEntries();
@ -527,7 +530,7 @@ class DictionaryController {
if (!Number.isFinite(target) || !Number.isFinite(index) || index === target) { return; } if (!Number.isFinite(target) || !Number.isFinite(index) || index === target) { return; }
this.swapDictionaryOptions(index, target); this.moveDictionaryOptions(index, target);
} }
_updateMainDictionarySelectOptions(dictionaries) { _updateMainDictionarySelectOptions(dictionaries) {