Skip to content

Commit 9803461

Browse files
committed
fix-bug: taskId:#4419
1 parent 1b0ae77 commit 9803461

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

app/components/TopBar/Breadcrumbs.jsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
import React from 'react'
1+
import React, { Component } from 'react'
2+
import PropTypes from 'prop-types'
23
import { observer, inject } from 'mobx-react'
34
import config from 'config'
45
import icons from 'file-icons-js'
56

7+
class BreadcrumbsContainer extends Component {
8+
componentDidUpdate () {
9+
this.refs.breadcrumbs.scrollLeft = this.refs.breadcrumbs.offsetWidth // 滑动条默认保持靠右
10+
}
11+
12+
render () {
13+
const { crumbs } = this.props
14+
return (
15+
<div className='breadcrumbs' ref='breadcrumbs'>
16+
{crumbs.map(crumb => (
17+
<Crumb node={crumb} key={crumb.path} />
18+
))}
19+
</div>
20+
)
21+
}
22+
}
23+
24+
BreadcrumbsContainer.propTypes = {
25+
crumbs: PropTypes.array
26+
}
27+
628
let Breadcrumbs = observer(({ fileNode }) => {
729
const pathComps = fileNode.path.split('/')
830
let rootName = config.workspaceName || config.projectName || 'Home'
931
if (config.isDefault) {
1032
rootName = 'Home'
1133
}
12-
const rootCrumb = {path: '/', name: rootName, isDir: true}
13-
const crumbs = pathComps.map(( pathComp, idx, pathComps ) => {
34+
const rootCrumb = { path: '/', name: rootName, isDir: true }
35+
const crumbs = pathComps.map((pathComp, idx, pathComps) => {
1436
if (pathComp === '') return rootCrumb
1537
return {
1638
name: pathComp,
17-
path: pathComps.slice(0, idx+1).join('/'),
39+
path: pathComps.slice(0, idx + 1).join('/'),
1840
gitStatus: fileNode.gitStatus,
19-
isDir: (idx !== pathComps.length - 1) // last pathComp isDir === false
41+
isDir: idx !== pathComps.length - 1 // last pathComp isDir === false
2042
}
2143
}, [])
2244

23-
return (
24-
<div className='breadcrumbs'>
25-
{crumbs.map(crumb => <Crumb node={crumb} key={crumb.path}/>)}
26-
</div>
27-
)
45+
return <BreadcrumbsContainer crumbs={crumbs} />
2846
})
2947

30-
Breadcrumbs = inject(state => {
48+
Breadcrumbs = inject((state) => {
3149
const activeTab = state.EditorTabState.activeTab
3250
const currentPath = activeTab && activeTab.file ? activeTab.file.path : ''
3351
let fileNode = state.FileTreeState.entities.get(currentPath)
@@ -36,15 +54,24 @@ Breadcrumbs = inject(state => {
3654
})(Breadcrumbs)
3755

3856
const SHOW_ICON = true
39-
const Crumb = ({node}) => {
57+
const Crumb = ({ node }) => {
4058
const props = { name: node.name }
4159
let fileClassName = 'crumb-node-name'
4260
if (!node.isDir) {
4361
fileClassName = `crumb-node-name git-${node.gitStatus ? node.gitStatus.toLowerCase() : 'none'}`
4462
}
4563
return (
4664
<div className='crumb'>
47-
{SHOW_ICON ? <i className={node.isDir ? 'fa fa-folder-o' : (icons.getClassWithColor(node.name) || 'fa fa-file-text-o')} style={{marginRight:'5px'}}></i>:null}
65+
{SHOW_ICON ? (
66+
<i
67+
className={
68+
node.isDir
69+
? 'fa fa-folder-o'
70+
: icons.getClassWithColor(node.name) || 'fa fa-file-text-o'
71+
}
72+
style={{ marginRight: '5px' }}
73+
/>
74+
) : null}
4875
<div className={fileClassName}>{node.name}</div>
4976
<div className='crumb-node-name'>{extension`siderBar${props}`}</div>
5077
</div>

app/styles/core-ui/Breadcrumbs.styl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
.breadcrumbs {
1616
noSelect();
1717
$breadcrumbs-height = 24px;
18+
overflow: auto;
1819

1920
display: flex;
2021
height: $breadcrumbs-height + 1px;
2122

2223
.crumb-node-name {
24+
white-space:nowrap;
2325
line-height: $breadcrumbs-height;
2426
}
2527

0 commit comments

Comments
 (0)