Skip to content

Commit d281a3c

Browse files
committed
fix(advancedmap): propertly detect duplicate keys
1 parent 19c1f2c commit d281a3c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# UnderScript Changelog
22

3+
## Version 0.62.5 (2025-05-20)
4+
1. Fixed (another) bug with advanced map
5+
36
## Version 0.62.4 (2025-04-14)
47
1. Fixed bug with advanced map
58

src/utils/settings/types/map2.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export default class AdvancedMap extends Setting {
5050
const line = $('<div class="item">');
5151
const options = { container: $('<div>'), name, disabled, remove: false, removeSetting() {}, key: `${key}.${id}`, child: true };
5252
const left = $(this.#keyType.element(this.#keyValue(lineValue[0], dataKey), (newValue) => {
53-
// TODO: validate this is how it's supposed to work
54-
const isInvalid = newValue !== lineValue[0] && data.some(([keyValue]) => keyValue === newValue);
53+
const [keyValue] = lineValue;
54+
const isInvalid = this.#isInvalid(data, keyValue, newValue);
5555
line.toggleClass('error', isInvalid);
56-
if (isInvalid || newValue === lineValue[0]) return;
56+
if (isInvalid || newValue === keyValue) return;
5757
lineValue[0] = newValue;
5858
save();
5959
}, {
@@ -127,6 +127,14 @@ export default class AdvancedMap extends Setting {
127127
]));
128128
}
129129

130+
#isInvalid(data, oldValue, newValue) {
131+
if (newValue === oldValue) return false;
132+
const encodedKeyValue = this.#keyType.encode(newValue);
133+
return data.some(
134+
([keyValue]) => this.#keyType.encode(keyValue) === encodedKeyValue,
135+
);
136+
}
137+
130138
get isRegistered() {
131139
const registered = mapTypes.has(this.#name);
132140
if (!registered) {

0 commit comments

Comments
 (0)