-
Notifications
You must be signed in to change notification settings - Fork 167
fix: after selecting and dragging text, the table still scrolls even after releasing the mouse. #328
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
Merged
Merged
fix: after selecting and dragging text, the table still scrolls even after releasing the mouse. #328
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f23c381
fix: enhance useScrollDrag with unified drag state cleanup
QdabuliuQ 2aa59f5
3.19.2
QdabuliuQ 0ce568c
fix: revert version to 3.19.1 in package.json
QdabuliuQ bae7ddc
test: add test to prevent scroll after text drop
QdabuliuQ 2a1f1b0
chore: translate comments in scroll test to English
QdabuliuQ 24b7327
fix: remove blur and visibilitychange cleanup in useScrollDrag
QdabuliuQ 1fcd09d
chore: remote comment
QdabuliuQ dc9f00e
chore: remove comments from scroll drag code and tests
QdabuliuQ a820beb
fix: refactor scroll drag event handling and test helper
QdabuliuQ b77332d
fix: handle drag events in useScrollDrag hook
QdabuliuQ 294ab97
chore: refactor scroll test for drag-and-drop behavior
QdabuliuQ f958296
chore: not block dragstart
zombieJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,12 @@ export default function useScrollDrag( | |
}); | ||
}; | ||
|
||
// 清理拖拽状态的统一函数 | ||
const clearDragState = () => { | ||
mouseDownLock = false; | ||
stopScroll(); | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可否移动到 onMouseUp 的位置,减少diff? |
||
const onMouseDown = (e: MouseEvent) => { | ||
// Skip if element set draggable | ||
if ((e.target as HTMLElement).draggable || e.button !== 0) { | ||
|
@@ -52,10 +58,15 @@ export default function useScrollDrag( | |
mouseDownLock = true; | ||
} | ||
}; | ||
|
||
const onMouseUp = () => { | ||
mouseDownLock = false; | ||
stopScroll(); | ||
clearDragState(); | ||
}; | ||
|
||
const onDragStart = () => { | ||
clearDragState(); | ||
}; | ||
|
||
const onMouseMove = (e: MouseEvent) => { | ||
if (mouseDownLock) { | ||
const mouseY = getPageXY(e, false); | ||
|
@@ -78,11 +89,16 @@ export default function useScrollDrag( | |
ele.addEventListener('mousedown', onMouseDown); | ||
ele.ownerDocument.addEventListener('mouseup', onMouseUp); | ||
ele.ownerDocument.addEventListener('mousemove', onMouseMove); | ||
|
||
ele.ownerDocument.addEventListener('dragstart', onDragStart); | ||
ele.ownerDocument.addEventListener('dragend', clearDragState); | ||
|
||
return () => { | ||
ele.removeEventListener('mousedown', onMouseDown); | ||
ele.ownerDocument.removeEventListener('mouseup', onMouseUp); | ||
ele.ownerDocument.removeEventListener('mousemove', onMouseMove); | ||
ele.ownerDocument.removeEventListener('dragstart', onDragStart); | ||
ele.ownerDocument.removeEventListener('dragend', clearDragState); | ||
stopScroll(); | ||
}; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.