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:
nate stemen 2020-03-18 10:27:20 -04:00 committed by Copybot
parent 3a2bdfe7f1
commit 3b027eba22

View file

@ -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 $(