feat: support clicking file tree item with ctrl key pressed to open in new tab

This commit is contained in:
EnixCoda 2019-02-22 10:52:32 +08:00
parent 8635186834
commit 220e6a23f6
No known key found for this signature in database
GPG key ID: 6825847C88AA329A
2 changed files with 13 additions and 6 deletions

View file

@ -3,6 +3,7 @@ import Icon from 'components/Icon'
import cx from 'utils/cx'
import LoadingIndicator from 'components/LoadingIndicator'
import { TreeNode } from 'utils/VisibleNodesGenerator'
import { detectOS, OperatingSystems } from 'utils/general'
function getIconType(node: TreeNode) {
switch (node.type) {
@ -25,7 +26,13 @@ type Props = {
}
export default class Node extends React.PureComponent<Props> {
onClick: React.MouseEventHandler = event => {
if (event.metaKey) return
if (
(detectOS() === OperatingSystems.macOS && event.metaKey) ||
(detectOS() === OperatingSystems.Windows && event.ctrlKey)
) {
// Open in new tab
return
}
event.preventDefault()
const { node, onClick } = this.props
onClick(node)

View file

@ -15,13 +15,13 @@ export function pick<T>(source: T, keys: string[]): Partial<T> {
return {} as Partial<T>
}
const OperatingSystems = {
Windows: 'Windows',
macOS: 'Macintosh',
others: 'unknown',
export enum OperatingSystems {
Windows = 'Windows',
macOS = 'Macintosh',
others = 'unknown',
}
function detectOS() {
export function detectOS(): OperatingSystems {
const {
navigator: { userAgent },
} = window