forgeplus-react/src/forge/Newfile/m_editor.js

84 lines
2.4 KiB
JavaScript

import React, { Component } from "react";
import Editor from "react-monaco-editor";
import UserSubmitComponent from "./UserSubmitComponent";
import "./index.css";
import "./editor.css";
class m_editor extends Component {
constructor(props) {
super(props);
this.state = {
editorValue: this.props.content,
};
}
componentDidUpdate=(prevProps)=>{
if(prevProps && this.props && this.props.content !== prevProps.content){
this.setState({
editorValue:this.props.content
})
}
}
changeEditor = (editorValue) => {
this.setState({
editorValue,
});
};
render() {
const { editorValue } = this.state;
const { readOnly, editorType, language , currentBranch } = this.props;
const editor_options = {
lineNumbers: "on",
wordWrap: true, //强制换行
selectOnLineNumbers: true,
lineHeight: 24,
renderLineHighlight: "line",
revealHorizontalRightPadding: 5,
placeholder:"请输入内容",
readOnly: readOnly,
cursorStyle: readOnly ? "underline-thin" : "line",
folding: true,
foldingStrategy: "indentation", // 代码可分小段折叠
automaticLayout: true, // 自适应布局
// overviewRulerBorder: false, // 不要滚动条的边框
// scrollBeyondLastLine: false, // 取消代码后面一大段空白
minimap: {
// 不要小地图
enabled: false,
},
};
return (
<React.Fragment>
<div>
<div className="branchTable" style={{border:"1px solid #eee"}}>
<Editor
height="400px"
language={language ? language : "plaintext"}
theme={"vs-grey"}
placeholder="请输入内容"
value={editorValue}
options={editor_options}
onChange={this.changeEditor}
editorWillMount={this.editorWillMount}
/>
</div>
{!readOnly && (
<div style={{marginTop:"20px",padding:"20px"}}>
<UserSubmitComponent
{...this.props}
{...this.state}
filepath={`${this.props.filepath}`}
content={editorValue}
editor_type={editorType}
currentBranch={currentBranch}
></UserSubmitComponent>
</div>
)}
</div>
</React.Fragment>
);
}
}
export default m_editor;