fix monaco editor layout with resizeObserve

dev_aliyun2
harry 5 years ago
parent 54a44ebb61
commit d4c032420f

@ -64,7 +64,7 @@ function getLanguageByMirrorName(mirror_name) {
export default ({ export default ({
width = '100%', width = '100%',
height = '100%', height = '445px',
value, value,
language = 'javascript', language = 'javascript',
options = {}, options = {},
@ -78,20 +78,9 @@ export default ({
const [init, setInit] = useState(false) const [init, setInit] = useState(false)
function onLayout() { function onLayout() {
if (window.ResizeObserver) {
const ro = new window.ResizeObserver(entries => {
for (let entry of entries) {
if (entry.target.offsetHeight > 0) {
editor.current.instance.layout()
}
}
})
ro.observe(editorEl.current.parentElement)
} else {
setTimeout(() => { setTimeout(() => {
editor.current.instance.layout() editor.current.instance.layout()
}, 100); }, 100)
}
} }
useEffect(() => { useEffect(() => {

@ -155,7 +155,7 @@ class MainContent extends Component {
<div style={{ display: (codeLoading ? 'block' : 'none'), textAlign: 'center' }}> <div style={{ display: (codeLoading ? 'block' : 'none'), textAlign: 'center' }}>
<span style={{ color: '#ddd', display: 'block' }}>正在加载中请稍后...</span> <span style={{ color: '#ddd', display: 'block' }}>正在加载中请稍后...</span>
</div> </div>
<div style={{ display: (codeLoading ? 'none' : 'block') }}> <div style={{ display: (codeLoading ? 'none' : 'block'), height: '100%' }}>
<CodeRepositoryViewContainer {...this.props} ></CodeRepositoryViewContainer> <CodeRepositoryViewContainer {...this.props} ></CodeRepositoryViewContainer>
</div> </div>
</React.Fragment> </React.Fragment>

@ -296,32 +296,6 @@ class CodeRepositoryViewContainer extends Component {
render() { render() {
return ( return (
// <React.Fragment>
// {this.props.isOnlyContainer == true ?
// React.Children.map(this.props.children, child => {
// if(!child) {
// return ''
// }
// return React.cloneElement(child, Object.assign({...this.state}, {
// loadRepoFiles: this.loadRepoFiles,
// onTreeSelect: this.onTreeSelect,
// onLoadData: this.onLoadData,
// }))
// })
// :
// <CodeRepositoryView {...this.props}
// {...this.state}
// showFilesDrawer={this.showFilesDrawer}
// loadRepoFiles={this.loadRepoFiles}
// onLoadData={this.onLoadData}
// onTreeSelect={ this.onTreeSelect }
// onRepositoryViewExpand={this.onRepositoryViewExpand}
// tabIndexChange={this.tabIndexChange}
// showSettingDrawer={this.showSettingDrawer}
// ></CodeRepositoryView> }
// </React.Fragment>
<React.Fragment> <React.Fragment>
{this.props.isOnlyContainer == true ? {this.props.isOnlyContainer == true ?
React.Children.map(this.props.children, child => { React.Children.map(this.props.children, child => {

Loading…
Cancel
Save