aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/dictionary-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-11 18:11:10 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-11 21:33:18 -0400
commite9c484e902cbd01e59db9cd9828574088a0190b8 (patch)
tree336163e6dbd0f149eb92338b652f009475465d02 /ext/js/pages/settings/dictionary-controller.js
parent1021067fc892782bae45f626603959e3d8f2c5bf (diff)
Improve the behaviour of the "Move to..." action (#1667)
Diffstat (limited to 'ext/js/pages/settings/dictionary-controller.js')
-rw-r--r--ext/js/pages/settings/dictionary-controller.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index c8a525ce..adb3edbd 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -169,7 +169,7 @@ class DictionaryEntry {
}
_move(offset) {
- this._dictionaryController.swapDictionaryOptions(this._index, this._index + offset);
+ this._dictionaryController.moveDictionaryOptions(this._index, this._index + offset);
}
_setMenuActionEnabled(menu, action, enabled) {
@@ -305,21 +305,24 @@ class DictionaryController {
modal.setVisible(true);
}
- async swapDictionaryOptions(index1, index2) {
+ async moveDictionaryOptions(currentIndex, targetIndex) {
const options = await this._settingsController.getOptions();
const {dictionaries} = options;
if (
- index1 < 0 || index1 >= dictionaries.length ||
- index2 < 0 || index2 >= dictionaries.length ||
- index1 === index2
+ currentIndex < 0 || currentIndex >= dictionaries.length ||
+ targetIndex < 0 || targetIndex >= dictionaries.length ||
+ currentIndex === targetIndex
) {
return;
}
+ const item = dictionaries.splice(currentIndex, 1)[0];
+ dictionaries.splice(targetIndex, 0, item);
+
await this._settingsController.modifyProfileSettings([{
- action: 'swap',
- path1: `dictionaries[${index1}]`,
- path2: `dictionaries[${index2}]`
+ action: 'set',
+ path: 'dictionaries',
+ value: dictionaries
}]);
await this._updateEntries();
@@ -527,7 +530,7 @@ class DictionaryController {
if (!Number.isFinite(target) || !Number.isFinite(index) || index === target) { return; }
- this.swapDictionaryOptions(index, target);
+ this.moveDictionaryOptions(index, target);
}
_updateMainDictionarySelectOptions(dictionaries) {