@@ -14,7 +14,7 @@ import {
1414export function useCodeReviewComment ( reviewContentRef : Ref < HTMLElement > , props : CodeReviewProps , ctx : SetupContext ) {
1515 const { outputFormat, allowComment, allowChecked } = toRefs ( props ) ;
1616 const ns = useNamespace ( 'code-review' ) ;
17- const { onMousedown } = useCodeReviewLineSelection ( reviewContentRef , props , updateLineNumbers , afterCheckLines ) ;
17+ const { onMousedown } = useCodeReviewLineSelection ( reviewContentRef , props , afterMouseup ) ;
1818 const commentLeft = ref ( - 100 ) ;
1919 const commentTop = ref ( - 100 ) ;
2020 let currentLeftLineNumber = - 1 ;
@@ -117,26 +117,6 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
117117 resetLeftTop ( ) ;
118118 }
119119 } ;
120- // 获代码行 取值方法
121- const getLineNumbers = ( currentNumber : number , currentNumbers : Array < number > , moveDirection : 'up' | 'down' ) => {
122- if ( currentNumber === - 1 ) {
123- // 当前行没数据不代表之前选中的没数据,此时返回原来的
124- return currentNumbers ;
125- }
126- if ( currentNumbers . length === 0 ) {
127- return [ currentNumber ] ;
128- }
129- const numbers = [ ...currentNumbers ] ;
130- let max = Math . max ( ...numbers ) ;
131- let min = Math . min ( ...numbers ) ;
132- if ( moveDirection === 'down' ) {
133- max = currentNumber ;
134- }
135- if ( moveDirection === 'up' ) {
136- min = currentNumber ;
137- }
138- return Array . from ( { length : max - min + 1 } , ( _ , i ) => i + min ) ;
139- } ;
140120 // 获取一些公共类和判断
141121 const getCommonClassAndJudge = ( ) => {
142122 const checkedLine = [ currentLeftLineNumbers , currentRightLineNumbers ] ;
@@ -211,13 +191,9 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
211191 }
212192 getDoubleCheckedLineCode ( shouldRenderClass ) ;
213193 }
214- function updateLineNumbers ( moveDirection : 'up' | 'down' ) {
215- currentLeftLineNumbers =
216- currentLeftLineNumber === - 1 ? currentLeftLineNumbers : getLineNumbers ( currentLeftLineNumber , currentLeftLineNumbers , moveDirection ) ;
217- currentRightLineNumbers =
218- currentRightLineNumber === - 1
219- ? currentRightLineNumbers
220- : getLineNumbers ( currentRightLineNumber , currentRightLineNumbers , moveDirection ) ;
194+ function updateLineNumbers ( { lefts, rights } : { lefts : number [ ] ; rights : number [ ] } ) {
195+ currentLeftLineNumbers = lefts ;
196+ currentRightLineNumbers = rights ;
221197 getCheckedLineCode ( false ) ;
222198 afterCheckLinesEmitData = {
223199 left : currentLeftLineNumber ,
@@ -230,6 +206,8 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
230206 } ;
231207 }
232208 const updateCheckedLineClass = ( ) => {
209+ const lineClassName = props . outputFormat === 'line-by-line' ? '.d2h-code-linenumber' : '.d2h-code-side-linenumber' ;
210+ allTrNodes = reviewContentRef . value . querySelectorAll ( lineClassName ) ;
233211 getCheckedLineCode ( true ) ;
234212 } ;
235213 // 还原样式
@@ -280,6 +258,10 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
280258 function afterCheckLines ( ) {
281259 ctx . emit ( 'afterCheckLines' , afterCheckLinesEmitData ) ;
282260 }
261+ function afterMouseup ( lineNumbers : { lefts : number [ ] ; rights : number [ ] } ) {
262+ updateLineNumbers ( lineNumbers ) ;
263+ afterCheckLines ( ) ;
264+ }
283265 // 图标或者单行的点击
284266 const onCommentIconClick = ( e : Event ) => {
285267 if ( e ) {
0 commit comments