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 cx from 'utils/cx'
|
||||||
import LoadingIndicator from 'components/LoadingIndicator'
|
import LoadingIndicator from 'components/LoadingIndicator'
|
||||||
import { TreeNode } from 'utils/VisibleNodesGenerator'
|
import { TreeNode } from 'utils/VisibleNodesGenerator'
|
||||||
|
import { detectOS, OperatingSystems } from 'utils/general'
|
||||||
|
|
||||||
function getIconType(node: TreeNode) {
|
function getIconType(node: TreeNode) {
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
|
|
@ -25,7 +26,13 @@ type Props = {
|
||||||
}
|
}
|
||||||
export default class Node extends React.PureComponent<Props> {
|
export default class Node extends React.PureComponent<Props> {
|
||||||
onClick: React.MouseEventHandler = event => {
|
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()
|
event.preventDefault()
|
||||||
const { node, onClick } = this.props
|
const { node, onClick } = this.props
|
||||||
onClick(node)
|
onClick(node)
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ export function pick<T>(source: T, keys: string[]): Partial<T> {
|
||||||
return {} as Partial<T>
|
return {} as Partial<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
const OperatingSystems = {
|
export enum OperatingSystems {
|
||||||
Windows: 'Windows',
|
Windows = 'Windows',
|
||||||
macOS: 'Macintosh',
|
macOS = 'Macintosh',
|
||||||
others: 'unknown',
|
others = 'unknown',
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectOS() {
|
export function detectOS(): OperatingSystems {
|
||||||
const {
|
const {
|
||||||
navigator: { userAgent },
|
navigator: { userAgent },
|
||||||
} = window
|
} = window
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue