Skip to content

Commit 76ac790

Browse files
committed
Refactor KeyLayoutInfo component to streamline key updates and improve data handling. Removed unused 'd' property, enhanced the updateSelectedKey function to include additional properties from keyToLoad, and simplified the updates for coordMapIndex and encoderIndex. Updated the way new layout copies are created for better performance and clarity.
1 parent 4584dd7 commit 76ac790

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/renderer/src/components/KeyLayoutInfo.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const tmpKey = ref<{
208208
h: number | ''
209209
w2: number | ''
210210
h2: number | ''
211-
d: boolean | ''
211+
212212
matrix: (number | '')[]
213213
variant: (number | '')[]
214214
coordMapIndex?: number | ''
@@ -225,7 +225,7 @@ const tmpKey = ref<{
225225
h: 1,
226226
w2: 0,
227227
h2: 0,
228-
d: false,
228+
229229
matrix: ['', ''],
230230
variant: ['', ''],
231231
coordMapIndex: '',
@@ -261,13 +261,21 @@ const updateSelectedKey = () => {
261261
// only load overlapping data from all selected keys
262262
263263
tmpKey.value = {
264-
...keyToLoad
265-
}
266-
if (keyToLoad.variant == undefined) {
267-
tmpKey.value.variant = ['', '']
268-
}
269-
if (keyToLoad.matrix == undefined) {
270-
tmpKey.value.matrix = ['', '']
264+
x: keyToLoad.x,
265+
y: keyToLoad.y,
266+
x2: keyToLoad.x2 ?? '',
267+
y2: keyToLoad.y2 ?? '',
268+
w: keyToLoad.w,
269+
h: keyToLoad.h,
270+
w2: keyToLoad.w2 ?? '',
271+
h2: keyToLoad.h2 ?? '',
272+
r: keyToLoad.r,
273+
rx: keyToLoad.rx,
274+
ry: keyToLoad.ry,
275+
matrix: keyToLoad.matrix ?? ['', ''],
276+
variant: keyToLoad.variant ?? ['', ''],
277+
coordMapIndex: keyToLoad.coordMapIndex ?? '',
278+
encoderIndex: keyToLoad.encoderIndex ?? ''
271279
}
272280
} else {
273281
// set every property that has different values to ""
@@ -284,7 +292,6 @@ const updateSelectedKey = () => {
284292
h: '',
285293
w2: '',
286294
h2: '',
287-
d: '',
288295
r: '',
289296
rx: '',
290297
ry: ''
@@ -329,16 +336,12 @@ const updateKey = () => {
329336
330337
// Handle coordMapIndex only if it was explicitly changed
331338
if (tmpKey.value.coordMapIndex !== '') {
332-
updates.coordMapIndex = !isNaN(tmpKey.value.coordMapIndex as any)
333-
? Number(tmpKey.value.coordMapIndex)
334-
: ''
339+
updates.coordMapIndex = Number(tmpKey.value.coordMapIndex)
335340
}
336341
337342
// Handle encoderIndex only if it was explicitly changed
338343
if (tmpKey.value.encoderIndex !== '') {
339-
updates.encoderIndex = !isNaN(Number(tmpKey.value.encoderIndex))
340-
? Number(tmpKey.value.encoderIndex)
341-
: undefined
344+
updates.encoderIndex = Number(tmpKey.value.encoderIndex)
342345
}
343346
344347
// Handle matrix updates
@@ -380,7 +383,7 @@ const updateKey = () => {
380383
}
381384
382385
// Update the key in our new layout copy
383-
newLayout[keyIndex] = { ...newLayout[keyIndex], ...updates }
386+
newLayout[keyIndex] = Object.assign(newLayout[keyIndex], updates)
384387
savePartialLayout(newLayout)
385388
})
386389

0 commit comments

Comments
 (0)