mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: support clicking file tree item with ctrl key pressed to open in new tab
This commit is contained in:
parent
8635186834
commit
220e6a23f6
2 changed files with 13 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue