fix: prevent blocking history navigation shortcut

This commit is contained in:
EnixCoda 2021-06-02 10:05:01 +08:00
parent e70f31567b
commit e1495fef45
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -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
}