mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 20:00:29 +01:00
Don't trigger hotkeys within sidebar edit input
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user