mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 23:41:18 +02: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(
|
const handleEditKeyDown = useCallback(
|
||||||
async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
async (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation(); // Don't trigger other tree keys (like arrows)
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case 'Enter':
|
case 'Enter':
|
||||||
if (editing) {
|
if (editing) {
|
||||||
@@ -331,6 +331,7 @@ function TreeItem_<T extends { id: string }>({
|
|||||||
const { defaultValue, placeholder } = getEditOptions(node.item);
|
const { defaultValue, placeholder } = getEditOptions(node.item);
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
|
data-disable-hotkey
|
||||||
ref={handleEditFocus}
|
ref={handleEditFocus}
|
||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
|||||||
@@ -179,18 +179,22 @@ function handleKeyDown(e: KeyboardEvent) {
|
|||||||
if (e.metaKey) currentKeysWithModifiers.add('Meta');
|
if (e.metaKey) currentKeysWithModifiers.add('Meta');
|
||||||
if (e.shiftKey) currentKeysWithModifiers.add('Shift');
|
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[] = [];
|
const executed: string[] = [];
|
||||||
outer: for (const { action, callback, options } of jotaiStore.get(sortedCallbacksAtom)) {
|
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[]][]) {
|
for (const [hkAction, hkKeys] of Object.entries(hotkeys) as [HotkeyAction, string[]][]) {
|
||||||
if (hkAction !== action) {
|
if (hkAction !== action) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user