From e1495fef45fd454de864242ddcb5d31f54c27a6f Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Wed, 2 Jun 2021 10:05:01 +0800 Subject: [PATCH] fix: prevent blocking history navigation shortcut --- src/driver/core/FileExplorer.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/driver/core/FileExplorer.ts b/src/driver/core/FileExplorer.ts index 8240357..6f82fc1 100644 --- a/src/driver/core/FileExplorer.ts +++ b/src/driver/core/FileExplorer.ts @@ -3,6 +3,7 @@ import { GetCreatedMethod, MethodCreator } from 'driver/connect' import { platform } from 'platforms' import { Config } from 'utils/config/helper' import * as DOMHelper from 'utils/DOMHelper' +import { OperatingSystems, os } from 'utils/general' import { VisibleNodes, VisibleNodesGenerator } from 'utils/VisibleNodesGenerator' export type Props = { @@ -132,6 +133,10 @@ export const handleKeyDown: BoundMethodCreator<[React.KeyboardEvent]> = dispatch break case 'ArrowLeft': + if (wouldBlockHistoryNavigation(event)) { + muteEvent = false + break + } if (expandedNodes.has(focusedNode.path)) { dispatch.call(toggleNodeExpansion, focusedNode, { recursive: event.altKey }) } else { @@ -145,6 +150,10 @@ export const handleKeyDown: BoundMethodCreator<[React.KeyboardEvent]> = dispatch // consider the two keys as 'confirm' key case 'ArrowRight': + if (wouldBlockHistoryNavigation(event)) { + muteEvent = false + break + } // expand node or focus on first content node or redirect to file page if (focusedNode.type === 'tree') { if (expandedNodes.has(focusedNode.path)) { @@ -305,3 +314,8 @@ export const expandTo: BoundMethodCreator<[string[]]> = dispatch => async curren visibleNodesGenerator.focusNode(nodeExpandedTo) } } + +function wouldBlockHistoryNavigation(event: React.KeyboardEvent) { + // Alt + left/right is usually history navigation shortcut on OS other than macOS + return os !== OperatingSystems.macOS && event.altKey +}