@@ -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 , updateLineNumbers ) ;
17+ const { onMousedown } = useCodeReviewLineSelection ( reviewContentRef , props , updateLineNumbers , updateLineNumbers , afterCheckLines ) ;
1818 const commentLeft = ref ( - 100 ) ;
1919 const commentTop = ref ( - 100 ) ;
2020 let currentLeftLineNumber = - 1 ;
@@ -24,6 +24,8 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
2424 let currentLeftLineNumbers : Array < number > = [ ] ;
2525 let currentRightLineNumbers : Array < number > = [ ] ;
2626 let checkedLineCodeString : Array < string > | Record < string , Array < string > > = { } ;
27+ let allTrNodes : NodeListOf < Element > = [ ] ;
28+ let afterCheckLinesEmitData : Record < string , any > ;
2729 watch (
2830 ( ) => outputFormat . value ,
2931 ( ) => {
@@ -137,11 +139,9 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
137139 } ;
138140 // 获取一些公共类和判断
139141 const getCommonClassAndJudge = ( ) => {
140- const lineClassName = props . outputFormat === 'line-by-line' ? '.d2h-code-linenumber' : '.d2h-code-side-linenumber' ;
141- const linenumberDom = reviewContentRef . value . querySelectorAll ( lineClassName ) ;
142142 const checkedLine = [ currentLeftLineNumbers , currentRightLineNumbers ] ;
143143 return {
144- linenumberDom,
144+ linenumberDom : allTrNodes ,
145145 checkedLine,
146146 } ;
147147 } ;
@@ -217,6 +217,15 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
217217 currentRightLineNumbers =
218218 currentRightLineNumber === - 1 ? currentRightLineNumbers : getLineNumbers ( currentRightLineNumber , currentRightLineNumbers ) ;
219219 getCheckedLineCode ( false ) ;
220+ afterCheckLinesEmitData = {
221+ left : currentLeftLineNumber ,
222+ right : currentRightLineNumber ,
223+ details : {
224+ lefts : currentLeftLineNumbers ,
225+ rights : currentRightLineNumbers ,
226+ codes : checkedLineCodeString ,
227+ } ,
228+ } ;
220229 }
221230 const updateCheckedLineClass = ( ) => {
222231 getCheckedLineCode ( true ) ;
@@ -266,6 +275,9 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
266275 // 点击添加评论图标触发的事件
267276 ctx . emit ( 'addComment' , obj ) ;
268277 } ;
278+ function afterCheckLines ( ) {
279+ ctx . emit ( 'afterCheckLines' , afterCheckLinesEmitData ) ;
280+ }
269281 // 图标或者单行的点击
270282 const onCommentIconClick = ( e : Event ) => {
271283 if ( e ) {
@@ -327,13 +339,19 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
327339 resetCommentClass ( ) ;
328340 } ;
329341
342+ const handleMouseDown = ( e : MouseEvent ) => {
343+ const lineClassName = props . outputFormat === 'line-by-line' ? '.d2h-code-linenumber' : '.d2h-code-side-linenumber' ;
344+ allTrNodes = reviewContentRef . value . querySelectorAll ( lineClassName ) ;
345+ onMousedown ( e ) ;
346+ } ;
347+
330348 const mouseEvent : Record < string , ( e : MouseEvent ) => void > = { } ;
331349 if ( allowComment . value ) {
332350 mouseEvent . onMousemove = onMouseMove ;
333351 mouseEvent . onMouseleave = onMouseleave ;
334352 }
335353 if ( props . allowChecked ) {
336- mouseEvent . onMousedown = onMousedown ;
354+ mouseEvent . onMousedown = handleMouseDown ;
337355 }
338356
339357 window . addEventListener ( 'scroll' , resetLeftTop ) ;
0 commit comments