mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-11 16:24:42 +00:00
Merge pull request #2662 from overleaf/cmg-dont-always-scroll
Stop file tree item being scrolled to if it is already in view GitOrigin-RevId: 7728bca54ab3bdc60537bd7699919240359e127d
This commit is contained in:
parent
3a2bdfe7f1
commit
3b027eba22
1 changed files with 19 additions and 3 deletions
|
@ -42,13 +42,29 @@ define(['base', 'ide/file-tree/util/iconTypeFromName'], function(
|
|||
$scope.$watch('entity.selected', function(isSelected) {
|
||||
if (isSelected) {
|
||||
$scope.$emit('entity-file:selected', $scope.entity)
|
||||
$scope.$applyAsync(function() {
|
||||
$element[0].scrollIntoView()
|
||||
})
|
||||
if (!_isEntryElVisible($element)) {
|
||||
$scope.$applyAsync(function() {
|
||||
$element[0].scrollIntoView()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function _isEntryElVisible($entryEl) {
|
||||
const viewportEl = $('.file-tree-list')
|
||||
const entryElTop = $entryEl.offset().top
|
||||
const entryElBottom = entryElTop + $entryEl.outerHeight()
|
||||
const entryListViewportElTop = viewportEl.offset().top
|
||||
const entryListViewportElBottom =
|
||||
entryListViewportElTop + viewportEl.height()
|
||||
|
||||
return (
|
||||
entryElTop >= entryListViewportElTop &&
|
||||
entryElBottom <= entryListViewportElBottom
|
||||
)
|
||||
}
|
||||
|
||||
$scope.draggableHelper = function() {
|
||||
if (ide.fileTreeManager.multiSelectedCount() > 0) {
|
||||
return $(
|
||||
|
|
Loading…
Reference in a new issue