fix c++语法高亮 代码不自动更新bug

video_transcode
harry 5 years ago
parent 1d2c420144
commit f5f22ca351

@ -11,7 +11,8 @@ import React, { useState, useRef, useEffect } from 'react';
import { Drawer, Tooltip, Badge } from 'antd';
import { fromStore, CNotificationHOC } from 'educoder';
import { connect } from 'react-redux';
import MonacoEditor from '@monaco-editor/react';
import { ControlledEditor } from '@monaco-editor/react';
import SettingDrawer from '../../components/monacoSetting';
import CONST from '../../../../constants';
import MyIcon from '../../../../common/components/MyIcon';
@ -47,8 +48,6 @@ function MyMonacoEditor(props, ref) {
return fromStore('oj_theme') || 'dark';
});
const [height, setHeight] = useState('calc(100% - 56px)');
const editorRef = useRef(null);
console.log(language, code, '-------========----------')
useEffect(() => {
setHeight(showOrHideControl ? 'calc(100% - 378px)' : 'calc(100% - 56px)');
@ -71,21 +70,10 @@ function MyMonacoEditor(props, ref) {
setTheme(value);
}
// 文本框内容变化时,记录文本框内容
const handleEditorChange = (_, monaco) => {
editorRef.current = monaco; // 获取当前monaco实例
}
useEffect(() => {
if (editorRef.current) {
editorRef.current.onDidChangeModelContent(e => { // 监听编辑器内容的变化
const val = editorRef.current.getValue();
onCodeChange(val);
});
}
}, [
editorRef.current
])
function onChangeHandler(ev, value) {
onCodeChange(value);
}
// 配置编辑器属性
const editorOptions = {
@ -152,14 +140,14 @@ function MyMonacoEditor(props, ref) {
<MyIcon className='code-icon' type="iconshezhi" onClick={handleShowDrawer} style={{ fontSize: '18px' }} />
</Tooltip>
</div>
<MonacoEditor
<ControlledEditor
height={height}
width="100%"
language={language && language.toLowerCase()}
value={code || ''}
options={editorOptions}
theme={theme} // dark || light
editorDidMount={handleEditorChange}
onChange={onChangeHandler}
/>
</div>

@ -26,7 +26,7 @@ const { Option } = Select;
const maps = {
language: [
{ title: 'C', key: 'C' },
{ title: 'C++', key: 'C++' },
{ title: 'C++', key: 'cpp' },
{ title: 'Python', key: 'Python' },
{ title: 'Java', key: 'Java' }
],

@ -57,7 +57,7 @@ const RightPane = (props) => {
timer = setInterval(function () {
clearInterval(timer);
timer = null;
saveUserCodeForInterval(identifier);
saveUserCodeForInterval(identifier, value);
}, 5000);
}
}
@ -99,13 +99,17 @@ const RightPane = (props) => {
});
}
const { getFieldDecorator } = props.form;
let language = hack.language
if (language === 'C++') {
language = 'cpp'
}
return (
<div className={'right_pane_code_wrap'}>
<MyMonacoEditor
notice={notice}
identifier={identifier}
language={hack.language}
language={language}
code={editor_code || hack.code}
hadCodeUpdate={hadCodeUpdate}
onCodeChange={handleCodeChange}

@ -102,13 +102,12 @@ export const getUserProgramDetail = (identifier, type) => {
export const saveUserCodeForInterval = (identifier, code) => {
return (dispatch, getState) => {
const { userCode } = getState().ojForUserReducer;
dispatch({
type: types.AUTO_UPDATE_CODE,
payload: true
});
fetchUpdateCode(identifier, {
code: Base64.encode(userCode)
code: Base64.encode(code)
}).then(res => {
if (res.data.status === 401) {
return;
@ -135,7 +134,6 @@ export const saveUserCodeForInterval = (identifier, code) => {
* @param {*} type 测评类型 debug | submit
*/
export const updateCode = (identifier, inputValue, type) => {
console.log(1111);
return (dispatch, getState) => {
const { userCode, isUpdateCode } = getState().ojForUserReducer;
if (isUpdateCode) {

Loading…
Cancel
Save