From 3b027eba2251372b8c2e2fc8cf2bdb9f641bd2f0 Mon Sep 17 00:00:00 2001 From: nate stemen Date: Wed, 18 Mar 2020 10:27:20 -0400 Subject: [PATCH] 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 --- .../controllers/FileTreeEntityController.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js b/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js index 3491006261..c0d2357226 100644 --- a/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js +++ b/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js @@ -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 $(