Don't trigger hotkeys within sidebar edit input

This commit is contained in:
Gregory Schier
2025-10-28 13:03:37 -07:00
parent 5b8114f6f3
commit a71fb8ed6c
2 changed files with 16 additions and 11 deletions

View File

@@ -156,7 +156,7 @@ function TreeItem_<T extends { id: string }>({
const handleEditKeyDown = useCallback(
async (e: React.KeyboardEvent<HTMLInputElement>) => {
e.stopPropagation();
e.stopPropagation(); // Don't trigger other tree keys (like arrows)
switch (e.key) {
case 'Enter':
if (editing) {
@@ -331,6 +331,7 @@ function TreeItem_<T extends { id: string }>({
const { defaultValue, placeholder } = getEditOptions(node.item);
return (
<input
data-disable-hotkey
ref={handleEditFocus}
defaultValue={defaultValue}
placeholder={placeholder}

View File

@@ -179,18 +179,22 @@ function handleKeyDown(e: KeyboardEvent) {
if (e.metaKey) currentKeysWithModifiers.add('Meta');
if (e.shiftKey) currentKeysWithModifiers.add('Shift');
// Don't trigger if the user is focused within an element that explicitly disableds hotkeys
if (document.activeElement?.closest('[data-disable-hotkey]')) {
return;
}
// Don't support certain single-key combinrations within inputs
if (
(e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) &&
currentKeysWithModifiers.size === 1 &&
(currentKeysWithModifiers.has('Backspace') || currentKeysWithModifiers.has('Delete'))
) {
return;
}
const executed: string[] = [];
outer: for (const { action, callback, options } of jotaiStore.get(sortedCallbacksAtom)) {
if (
(e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) &&
currentKeysWithModifiers.size === 1 &&
(currentKeysWithModifiers.has('Backspace') || currentKeysWithModifiers.has('Delete'))
) {
// Don't support Backspace-only modifiers within input fields. This is fairly brittle, so maybe there's a
// better way to do stuff like this in the future.
continue;
}
for (const [hkAction, hkKeys] of Object.entries(hotkeys) as [HotkeyAction, string[]][]) {
if (hkAction !== action) {
continue;