mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: problemconfig: selectionManager: fix subtask drag
This commit is contained in:
1 file changed
+18
-9
@@ -34,14 +34,14 @@ export function SelectionManager(props: SelectionManagerProps) {
|
|||||||
setEnd(0);
|
setEnd(0);
|
||||||
}, [JSON.stringify(cases)]);
|
}, [JSON.stringify(cases)]);
|
||||||
|
|
||||||
|
const selecting = React.useRef(false);
|
||||||
|
|
||||||
const handleMouseDown = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
const handleMouseDown = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
||||||
pos.x = event.pageX;
|
pos.x = event.pageX;
|
||||||
pos.y = event.pageY;
|
pos.y = event.pageY;
|
||||||
// Check if clicking on a selected testcase
|
// Check if clicking on a selected testcase (let drag handle it)
|
||||||
const selected = Array.from($('[data-selected="true"]'));
|
if ((event.target as HTMLElement).closest?.('[data-selected="true"]')) return;
|
||||||
for (const el of selected) {
|
selecting.current = true;
|
||||||
if (collide(el, { ...pos, width: 1, height: 1 })) return;
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line ts/no-use-before-define
|
// eslint-disable-next-line ts/no-use-before-define
|
||||||
document.body.addEventListener('mousemove', handleMouseMove);
|
document.body.addEventListener('mousemove', handleMouseMove);
|
||||||
// eslint-disable-next-line ts/no-use-before-define
|
// eslint-disable-next-line ts/no-use-before-define
|
||||||
@@ -55,6 +55,7 @@ export function SelectionManager(props: SelectionManagerProps) {
|
|||||||
}).fadeTo(12, 0.2);
|
}).fadeTo(12, 0.2);
|
||||||
}, [JSON.stringify(cases)]);
|
}, [JSON.stringify(cases)]);
|
||||||
const handleMouseMove = React.useCallback((event) => {
|
const handleMouseMove = React.useCallback((event) => {
|
||||||
|
if (!selecting.current) return;
|
||||||
pos.endX = event.pageX;
|
pos.endX = event.pageX;
|
||||||
pos.endY = event.pageY;
|
pos.endY = event.pageY;
|
||||||
$('#divSelectArea').css({
|
$('#divSelectArea').css({
|
||||||
@@ -64,9 +65,19 @@ export function SelectionManager(props: SelectionManagerProps) {
|
|||||||
width: Math.abs(event.pageX - pos.x),
|
width: Math.abs(event.pageX - pos.x),
|
||||||
});
|
});
|
||||||
}, [JSON.stringify(cases)]);
|
}, [JSON.stringify(cases)]);
|
||||||
const handleMouseUp = React.useCallback(() => {
|
const cleanupSelection = React.useCallback(() => {
|
||||||
|
selecting.current = false;
|
||||||
document.body.removeEventListener('mousemove', handleMouseMove);
|
document.body.removeEventListener('mousemove', handleMouseMove);
|
||||||
document.body.removeEventListener('mouseup', handleMouseUp);
|
document.body.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
$('#divSelectArea').remove();
|
||||||
|
$('body').css('cursor', 'default');
|
||||||
|
pos.x = pos.y = pos.endX = pos.endY = 0;
|
||||||
|
}, [JSON.stringify(cases)]);
|
||||||
|
const handleMouseUp = React.useCallback(() => {
|
||||||
|
if (!selecting.current) {
|
||||||
|
cleanupSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const caseEntries = Array.from($(`[data-subtaskid="${subtaskId}"]`));
|
const caseEntries = Array.from($(`[data-subtaskid="${subtaskId}"]`));
|
||||||
const selected = [];
|
const selected = [];
|
||||||
for (let i = 0; i < caseEntries.length; i += 1) {
|
for (let i = 0; i < caseEntries.length; i += 1) {
|
||||||
@@ -75,9 +86,7 @@ export function SelectionManager(props: SelectionManagerProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const sorted = selected.sort((a, b) => a - b);
|
const sorted = selected.sort((a, b) => a - b);
|
||||||
$('#divSelectArea').remove();
|
cleanupSelection();
|
||||||
$('body').css('cursor', 'default');
|
|
||||||
pos.x = pos.y = pos.endX = pos.endY = 0;
|
|
||||||
if (!sorted.length) return;
|
if (!sorted.length) return;
|
||||||
setStart(sorted[0]);
|
setStart(sorted[0]);
|
||||||
setEnd(sorted[selected.length - 1] + 1);
|
setEnd(sorted[selected.length - 1] + 1);
|
||||||
|
|||||||
Reference in new issue
Block a user