mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-05 09:32:53 +00:00
fix: editing chords messes up list
This commit is contained in:
@@ -2,6 +2,7 @@ import {persistentWritable} from "$lib/storage"
|
|||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import type {Chord} from "$lib/serial/chord"
|
import type {Chord} from "$lib/serial/chord"
|
||||||
import {deviceChords, deviceLayout, deviceSettings} from "$lib/serial/connection"
|
import {deviceChords, deviceLayout, deviceSettings} from "$lib/serial/connection"
|
||||||
|
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||||
|
|
||||||
export enum ChangeType {
|
export enum ChangeType {
|
||||||
Layout,
|
Layout,
|
||||||
@@ -89,7 +90,7 @@ export const layout = derived([overlay, deviceLayout], ([overlay, layout]) =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
export type ChordInfo = Chord &
|
export type ChordInfo = Chord &
|
||||||
ChangeInfo & {phraseChanged: boolean; actionsChanged: boolean} & {id: number[]}
|
ChangeInfo & {phraseChanged: boolean; actionsChanged: boolean; sortBy: string} & {id: number[]}
|
||||||
export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
||||||
chords
|
chords
|
||||||
.map<ChordInfo>(chord => {
|
.map<ChordInfo>(chord => {
|
||||||
@@ -98,6 +99,8 @@ export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
|||||||
const changedChord = overlay.chords.get(id)!
|
const changedChord = overlay.chords.get(id)!
|
||||||
return {
|
return {
|
||||||
id: chord.actions,
|
id: chord.actions,
|
||||||
|
// use the old phrase for stable editing
|
||||||
|
sortBy: chord.phrase.map(it => KEYMAP_CODES[it].id || it).join(),
|
||||||
actions: changedChord.actions,
|
actions: changedChord.actions,
|
||||||
phrase: changedChord.phrase,
|
phrase: changedChord.phrase,
|
||||||
actionsChanged: id !== JSON.stringify(changedChord.actions),
|
actionsChanged: id !== JSON.stringify(changedChord.actions),
|
||||||
@@ -107,6 +110,7 @@ export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
|||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
id: chord.actions,
|
id: chord.actions,
|
||||||
|
sortBy: chord.phrase.map(it => KEYMAP_CODES[it].id || it).join(),
|
||||||
actions: chord.actions,
|
actions: chord.actions,
|
||||||
phrase: chord.phrase,
|
phrase: chord.phrase,
|
||||||
phraseChanged: false,
|
phraseChanged: false,
|
||||||
@@ -115,5 +119,5 @@ export const chords = derived([overlay, deviceChords], ([overlay, chords]) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.phrase.map((it, i) => it - b.phrase[i]).find(it => it !== 0) ?? 0),
|
.sort(({sortBy: a}, {sortBy: b}) => a.localeCompare(b)),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user