rusackas commented on code in PR #39460:
URL: https://github.com/apache/superset/pull/39460#discussion_r3416925776


##########
superset-frontend/src/dashboard/components/UndoRedoKeyListeners/index.tsx:
##########
@@ -16,51 +16,51 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { PureComponent } from 'react';
+import { useCallback, useEffect } from 'react';
 import { HeaderProps } from '../Header/types';
 
 type UndoRedoKeyListenersProps = {
   onUndo: HeaderProps['onUndo'];
   onRedo: HeaderProps['onRedo'];
 };
 
-class UndoRedoKeyListeners extends PureComponent<UndoRedoKeyListenersProps> {
-  constructor(props: UndoRedoKeyListenersProps) {
-    super(props);
-    this.handleKeydown = this.handleKeydown.bind(this);
-  }
+function UndoRedoKeyListeners({ onUndo, onRedo }: UndoRedoKeyListenersProps) {
+  const handleKeydown = useCallback(
+    (event: KeyboardEvent) => {
+      const controlOrCommand = event.ctrlKey || event.metaKey;
+      if (controlOrCommand) {
+        const key = event.key.toLowerCase();
+        // Fall back to keyCode (90 = Z, 89 = Y) so undo/redo still work on
+        // non-Latin keyboard layouts where event.key is a different glyph.
+        const isZ = key === 'z' || event.keyCode === 90;
+        const isY = key === 'y' || event.keyCode === 89;
+        const isUndo = isZ && !event.shiftKey;
+        const isRedo = isY || (isZ && event.shiftKey);

Review Comment:
   Good call, switched both checks to `event.code` (and the tests) in 
11600c08c7. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to