import AceEditor from 'react-ace'; // 引用实例
import 'brace/mode/twilight'; // 引用自定义主题
import 'brace/mode/c_cpp'; // 定义为c_cpp代码高亮
import 'brace/ext/language_tools'; // 增加代码提示
// 增加需要自定义的代码提示
const completers = [
{
name: 'word',
value: 'word',
score: 100,
meta: 'keyword'
}
];
const complete = editor => {
editor.completers.push({
getCompletions: function (editors, session, pos, prefix, callback) {
callback(null, completers);
}
});
};
render(){
return(
<AceEditor
className={styles.codeEditor}
mode="c_cpp"
name="UNIQUE_ID_OF_DIV"
setOptions={{
enableBasicAutocompletion: false,
enableLiveAutocompletion: true,
enableSnippets: false,
showLineNumbers: true,
tabSize: 4
}}
style={{height: '98%', fontSize: '12px', border: '1px solid #d9d9d9'}}
theme={theme}
value={code}
width={width === 0 ? '100%' : `${width}px`}
onLoad={complete}
/>
)
}