Merge pull request #3905 from xyflow/fix/deletion-focused-input

Fix/deletion focused input
This commit is contained in:
Moritz Klack
2024-02-13 15:48:51 +01:00
committed by GitHub
5 changed files with 18 additions and 4 deletions
+1
View File
@@ -3,6 +3,7 @@
## 12.0.0-next.9 ## 12.0.0-next.9
- a better NodeResizer that works with subflows. Child nodes do not move when parent node gets resized and parent extent is taken into account - a better NodeResizer that works with subflows. Child nodes do not move when parent node gets resized and parent extent is taken into account
- don't delete node when input is focused and user presses Backspace + Ctrl (or any other mod key)
## 12.0.0-next.8 ## 12.0.0-next.8
+6
View File
@@ -92,6 +92,12 @@ export function useKeyPress(
} else { } else {
pressedKeys.current.delete(event[keyOrCode]); pressedKeys.current.delete(event[keyOrCode]);
} }
// fix for Mac: when cmd key is pressed, keyup is not triggered for any other key, see: https://stackoverflow.com/questions/27380018/when-cmd-key-is-kept-pressed-keyup-is-not-triggered-for-any-other-key
if (event.key === 'Meta') {
pressedKeys.current.clear();
}
modifierPressed.current = false; modifierPressed.current = false;
}; };
+1
View File
@@ -7,6 +7,7 @@
- a better NodeResizer (child nodes do not move when parent node gets resized) - a better NodeResizer (child nodes do not move when parent node gets resized)
- fix `on:panecontextmenu` - fix `on:panecontextmenu`
- add `role="button"` to `<EdgeLabel />` to prevent a11y warnings - add `role="button"` to `<EdgeLabel />` to prevent a11y warnings
- don't delete node when input is focused and user presses Backspace + Ctrl (or any other mod key)
## 0.0.35 ## 0.0.35
@@ -113,7 +113,15 @@
{ {
...deleteKeyDefinition, ...deleteKeyDefinition,
enabled: deleteKeyDefinition.key !== null, enabled: deleteKeyDefinition.key !== null,
callback: (detail) => !isInputDOMNode(detail.originalEvent) && deleteKeyPressed.set(true) callback: (detail) => {
const isModifierKey =
detail.originalEvent.ctrlKey ||
detail.originalEvent.metaKey ||
detail.originalEvent.shiftKey;
if (!isModifierKey && !isInputDOMNode(detail.originalEvent)) {
deleteKeyPressed.set(true);
}
}
} }
], ],
type: 'keydown' type: 'keydown'
+1 -3
View File
@@ -37,11 +37,9 @@ export function isInputDOMNode(event: KeyboardEvent): boolean {
// using composed path for handling shadow dom // using composed path for handling shadow dom
const target = (event.composedPath?.()?.[0] || event.target) as HTMLElement; const target = (event.composedPath?.()?.[0] || event.target) as HTMLElement;
const isInput = inputTags.includes(target?.nodeName) || target?.hasAttribute('contenteditable'); const isInput = inputTags.includes(target?.nodeName) || target?.hasAttribute('contenteditable');
// we want to be able to do a multi selection event if we are in an input field
const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey;
// when an input field is focused we don't want to trigger deletion or movement of nodes // when an input field is focused we don't want to trigger deletion or movement of nodes
return (isInput && !isModifierKey) || !!target?.closest('.nokey'); return isInput || !!target?.closest('.nokey');
} }
export const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => 'clientX' in event; export const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => 'clientX' in event;