mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-21 01:12:59 +00:00
fix: disallow null inputs when editing
feat: allow special inputs while creating a chord input fixes #93
This commit is contained in:
@@ -28,7 +28,12 @@
|
||||
function keydown(event: KeyboardEvent) {
|
||||
if (!editing) return
|
||||
event.preventDefault()
|
||||
pressedKeys.add(inputToAction(event, get(serialPort)?.device === "X")!)
|
||||
const input = inputToAction(event, get(serialPort)?.device === "X")
|
||||
if (input == undefined) {
|
||||
alert("Invalid key")
|
||||
return
|
||||
}
|
||||
pressedKeys.add(input)
|
||||
pressedKeys = pressedKeys
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {KEYMAP_IDS, specialKeycodes} from "$lib/serial/keymap-codes"
|
||||
import {tick} from "svelte"
|
||||
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
||||
import {changes, ChangeType} from "$lib/undo-redo"
|
||||
import type {ChordInfo} from "$lib/undo-redo"
|
||||
import {scale} from "svelte/transition"
|
||||
@@ -26,6 +24,7 @@
|
||||
} else if (event.key === "Delete") {
|
||||
deleteAction(cursorPosition)
|
||||
} else {
|
||||
if (event.key === "Shift") return
|
||||
const action = inputToAction(event, get(serialPort)?.device === "X")
|
||||
if (action !== undefined) {
|
||||
insertAction(cursorPosition, action)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {KEYMAP_IDS, KEYMAP_KEYCODES, specialKeycodes} from "$lib/serial/keymap-codes"
|
||||
import {KEYMAP_IDS, KEYMAP_KEYCODES} from "$lib/serial/keymap-codes"
|
||||
|
||||
export function inputToAction(event: KeyboardEvent, useKeycodes?: boolean): number | undefined {
|
||||
if (useKeycodes) {
|
||||
return KEYMAP_KEYCODES.get(event.code)
|
||||
} else {
|
||||
return KEYMAP_IDS.get(event.key)?.code ?? specialKeycodes.get(event.key)
|
||||
return KEYMAP_IDS.get(event.key)?.code ?? KEYMAP_KEYCODES.get(event.code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user