Skip to content

Commit 24c6c2d

Browse files
authored
Merge pull request #36028 from nextcloud/backport/36024/stable25
[stable25] Fix scrolling while dragging in file list view
2 parents 8392f8b + 4f6298d commit 24c6c2d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

apps/files/js/files.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ var dragOptions={
449449
revert: 'invalid',
450450
revertDuration: 300,
451451
opacity: 0.7,
452-
appendTo: 'body',
453452
cursorAt: { left: 24, top: 18 },
454453
helper: createDragShadow,
455454
cursor: 'move',
@@ -482,23 +481,26 @@ var dragOptions={
482481
$('.crumbmenu').removeClass('canDropChildren');
483482
},
484483
drag: function(event, ui) {
485-
var scrollingArea = FileList.$container;
486-
var currentScrollTop = $(scrollingArea).scrollTop();
487-
var scrollArea = Math.min(Math.floor($(window).innerHeight() / 2), 100);
488-
489-
var bottom = $(window).innerHeight() - scrollArea;
490-
var top = $(window).scrollTop() + scrollArea;
491-
if (event.pageY < top) {
492-
$(scrollingArea).animate({
493-
scrollTop: currentScrollTop - 10
494-
}, 400);
495-
496-
} else if (event.pageY > bottom) {
497-
$(scrollingArea).animate({
498-
scrollTop: currentScrollTop + 10
499-
}, 400);
500-
}
484+
/** @type {JQuery<HTMLDivElement>} */
485+
const scrollingArea = FileList.$container;
486+
487+
// Get the top and bottom scroll trigger y positions
488+
const containerHeight = scrollingArea.innerHeight() ?? 0
489+
const scrollTriggerArea = Math.min(Math.floor(containerHeight / 2), 100);
490+
const bottomTriggerY = containerHeight - scrollTriggerArea;
491+
const topTriggerY = scrollTriggerArea;
492+
493+
// Get the cursor position relative to the container
494+
const containerOffset = scrollingArea.offset() ?? {left: 0, top: 0}
495+
const cursorPositionY = event.pageY - containerOffset.top
501496

497+
const currentScrollTop = scrollingArea.scrollTop() ?? 0
498+
499+
if (cursorPositionY < topTriggerY) {
500+
scrollingArea.scrollTop(currentScrollTop - 10)
501+
} else if (cursorPositionY > bottomTriggerY) {
502+
scrollingArea.scrollTop(currentScrollTop + 10)
503+
}
502504
}
503505
};
504506
// sane browsers support using the distance option

0 commit comments

Comments
 (0)