Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xingyan/fix code review #1916

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading