Skip to content

Commit

Permalink
Xingyan/fix code review (#1916) (#1917)
Browse files Browse the repository at this point in the history
* fix(CodeReview): 修复拖拽时记录的行号区间错误的问题
  • Loading branch information
xingyan95 authored Nov 25, 2024
1 parent 2d90a56 commit aedd851
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
}
};
// 获代码行 取值方法
const getLineNumbers = (currentNumber: number, currentNumbers: Array<number>) => {
const getLineNumbers = (currentNumber: number, currentNumbers: Array<number>, moveDirection: 'up' | 'down') => {
if (currentNumber === -1) {
// 当前行没数据不代表之前选中的没数据,此时返回原来的
return currentNumbers;
Expand All @@ -129,12 +129,12 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
const numbers = [...currentNumbers];
let max = Math.max(...numbers);
let min = Math.min(...numbers);
if (currentNumber < min) {
min = currentNumber;
}
if (currentNumber > max) {
if (moveDirection === 'down') {
max = currentNumber;
}
if (moveDirection === 'up') {
min = currentNumber;
}
return Array.from({ length: max - min + 1 }, (_, i) => i + min);
};
// 获取一些公共类和判断
Expand Down Expand Up @@ -211,11 +211,13 @@ export function useCodeReviewComment(reviewContentRef: Ref<HTMLElement>, props:
}
getDoubleCheckedLineCode(shouldRenderClass);
}
function updateLineNumbers() {
function updateLineNumbers(moveDirection: 'up' | 'down') {
currentLeftLineNumbers =
currentLeftLineNumber === -1 ? currentLeftLineNumbers : getLineNumbers(currentLeftLineNumber, currentLeftLineNumbers);
currentLeftLineNumber === -1 ? currentLeftLineNumbers : getLineNumbers(currentLeftLineNumber, currentLeftLineNumbers, moveDirection);
currentRightLineNumbers =
currentRightLineNumber === -1 ? currentRightLineNumbers : getLineNumbers(currentRightLineNumber, currentRightLineNumbers);
currentRightLineNumber === -1
? currentRightLineNumbers
: getLineNumbers(currentRightLineNumber, currentRightLineNumbers, moveDirection);
getCheckedLineCode(false);
afterCheckLinesEmitData = {
left: currentLeftLineNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { findParentTrNode } from '../utils';
export function useCodeReviewLineSelection(
reviewContentRef: Ref<HTMLElement>,
props: CodeReviewProps,
mouseMoveCb: () => void,
mouseMoveCb: (moveDirection: 'up' | 'down') => void,
mouseupCb: () => void
) {
const ns = useNamespace('code-review');
Expand All @@ -16,6 +16,7 @@ export function useCodeReviewLineSelection(
let isClickedLeft: boolean | undefined;
let shouldClear: boolean;
let isMouseMoved: boolean;
let startClientY: number;

const onMousedown = (e: MouseEvent) => {
// 鼠标左键按下
Expand Down Expand Up @@ -44,6 +45,7 @@ export function useCodeReviewLineSelection(
dragging = true;
shouldClear = true;
isMouseMoved = false;
startClientY = e.clientY;
e.preventDefault();
e.stopPropagation();
document.addEventListener('mousemove', onMousemove);
Expand Down Expand Up @@ -74,7 +76,7 @@ export function useCodeReviewLineSelection(
if (endIndex === -1) {
return;
}
mouseMoveCb();
mouseMoveCb(e.clientY > startClientY ? 'down' : 'up');
if (startIndex > endIndex) {
[startIndex, endIndex] = [endIndex, startIndex];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/devui-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-devui",
"version": "1.6.24",
"version": "1.6.25",
"license": "MIT",
"description": "DevUI components based on Vite and Vue3",
"keywords": [
Expand Down

0 comments on commit aedd851

Please sign in to comment.