From 554ff5b175c600ad08cfc789e96370fc6dfcf0c2 Mon Sep 17 00:00:00 2001
From: linlu <527100546@qq.com>
Date: Thu, 14 Jul 2022 11:13:09 +0800
Subject: [PATCH] fix
---
src/forge/Newfile/m_editor.js | 35 ++++++++++++++++++++---------------
src/forge/Quality/index.js | 34 ++++++++++++++++++++++------------
2 files changed, 42 insertions(+), 27 deletions(-)
diff --git a/src/forge/Newfile/m_editor.js b/src/forge/Newfile/m_editor.js
index 58a79403..83ebabed 100644
--- a/src/forge/Newfile/m_editor.js
+++ b/src/forge/Newfile/m_editor.js
@@ -1,5 +1,5 @@
import React, { Component } from "react";
-import {UnControlled as CodeMirror} from 'react-codemirror2';
+import { UnControlled as CodeMirror } from 'react-codemirror2';
import 'codemirror/addon/selection/active-line.js';
import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/mode/clike/clike';
@@ -13,28 +13,32 @@ import "./editor.css";
class m_editor extends Component {
constructor(props) {
super(props);
+ this.editorDidMount = this.editorDidMount.bind(this)
this.state = {
editorValue: this.props.content,
- changeValue:this.props.content,
- prevHeight:0
+ changeValue: this.props.content,
+ prevHeight: 0
};
}
- componentDidUpdate=(prevProps)=>{
- if(prevProps && this.props && this.props.content !== prevProps.content){
+ componentDidUpdate = (prevProps) => {
+ if (prevProps && this.props && this.props.content !== prevProps.content) {
this.setState({
- editorValue:this.props.content
+ editorValue: this.props.content
})
}
}
- changeEditor = (editorValue,data) => {
+ changeEditor = (editorValue, data) => {
this.setState({
- changeValue:editorValue.getValue(),
+ changeValue: editorValue.getValue(),
});
};
-
+ editorDidMount = (cm, data) => {
+ if (this.props.goLine)
+ cm.scrollIntoView({ line: this.props.goLine, char: 1 }, 200)
+ };
render() {
- const { editorValue , changeValue } = this.state;
- const { readOnly, editorType, currentBranch , descName , checkName } = this.props;
+ const { editorValue, changeValue } = this.state;
+ const { readOnly, editorType, currentBranch, descName, checkName } = this.props;
const editor_options = {
lineNumbers: "on",
lineWrapping: true, //强制换行
@@ -42,7 +46,7 @@ class m_editor extends Component {
lineHeight: 24,
renderLineHighlight: "line",
revealHorizontalRightPadding: 5,
- placeholder:"请输入内容",
+ placeholder: "请输入内容",
readOnly: readOnly,
cursorStyle: readOnly ? "underline-thin" : "line",
folding: true,
@@ -50,7 +54,7 @@ class m_editor extends Component {
automaticLayout: true, // 自适应布局
overviewRulerBorder: false, // 不要滚动条的边框
scrollBeyondLastLine: false, // 取消代码后面一大段空白
- styleActiveLine:true,//光标代码高亮
+ styleActiveLine: true,//光标代码高亮
minimap: {
// 不要小地图
enabled: false,
@@ -64,10 +68,11 @@ class m_editor extends Component {
value={editorValue}
options={editor_options}
onChange={this.changeEditor}
+ onUpdate={this.editorDidMount}
/>
{!readOnly && (
-
)}
);
diff --git a/src/forge/Quality/index.js b/src/forge/Quality/index.js
index 545010b0..6930d970 100644
--- a/src/forge/Quality/index.js
+++ b/src/forge/Quality/index.js
@@ -17,7 +17,7 @@ function Quality(props){
const [statuts,setStatus] = useState(-1)
const [questionList,setQuestionList] = useState([]) //对应问题列表
const [isDetail,setDetail] = useState(false) //对应问题列表
- const [codeDetailValue,setCodeDetailValue] = useState("") //对应问题列表
+ const [codeDetailValue,setCodeDetailValue] = useState({}) //对应问题列表
const [indexValue,setIndexValue] = useState(null)
const severityList = {
'BLOCKER': "致命缺陷",
@@ -32,8 +32,12 @@ function Quality(props){
useEffect(()=>{
if(indexValue){
- const domBox = document.getElementsByClassName('CodeMirror-code')[0].childNodes[indexValue]
- domBox.style.cssText='border:1px solid red; padding: 5px;border-radius: 10px;color: black;background: lemonchiffon;'
+ // document.getElementById('htmlDOM').innerHTML
+ const domBox = document.getElementsByClassName('CodeMirror-code')[0].childNodes[indexValue.line - 1]
+ const divs = document.createElement("div");
+ divs.innerHTML = questionList[indexValue.index].message;
+ domBox.appendChild(divs)
+ divs.style.cssText='border:1px solid red; padding: 5px;border-radius: 10px;color: black;background: lemonchiffon;'
}
},[indexValue])
const getTask = () => {
@@ -67,6 +71,7 @@ function Quality(props){
const getTaskDetail = (task_id) => {
axios.get(`/${owner}/${projectsId}/sonar_tasks/type_detail.json?task_id=${task_id}&type=ALL`)
.then(({data:{data,message,status}})=>{
+ document.body.scrollIntoView()
setStatus(0)
setQuestionList(data);
}).catch(function (error) {
@@ -78,20 +83,24 @@ function Quality(props){
setStatus(2)
getTaskData()
}
- const getCodeDetailData = (item) => {
+ const getCodeDetailData = (item,index) => {
axios.get(`/${owner}/${projectsId}/sonar_tasks/code_source.json?component=${item.component}&task_id=${sonarList.task_id}`)
.then(({data:{data,message,status}})=>{
- data.splice(item.line,0,{code:document.getElementById('htmlDOM').innerHTML,line:item.line})
+ document.body.scrollIntoView()
+ // data.splice(item.line,0,{code:document.getElementById('htmlDOM').innerHTML,line:item.line})
const text = data.map(item => item.code).join("\n")
const dom = document.createElement("div");
dom.innerHTML = text;
setDetail(true)
- setCodeDetailValue(dom.innerText)
- setIndexValue(item.line?item.line:'')
+ setCodeDetailValue({content:dom.innerText,line:item.line + 5})
+ setIndexValue({
+ line:item.line,
+ index
+ })
})
}
- const handleCodeDetail = (item) => {
- getCodeDetailData(item)
+ const handleCodeDetail = (item,index) => {
+ getCodeDetailData(item,index)
}
const handleBack = () => {
setDetail(false)
@@ -117,7 +126,7 @@ function Quality(props){
{questionList.map((item,index)=>{
- return
handleCodeDetail(item)}>
+ return
handleCodeDetail(item,index)}>
{item.component}
{item.message}
@@ -129,10 +138,11 @@ function Quality(props){
:
-
+