overleaf/services/web/frontend/js/ide/file-tree/controllers/FileTreeEntityController.js
Alf Eaton 6ab9fffb49 Remove Angular file tree modal code (#4198)
GitOrigin-RevId: feeae54575cce8b315b4e6bb0df3e17405025855
2021-06-16 02:05:58 +00:00

52 lines
1.7 KiB
JavaScript

import App from '../../../base'
import iconTypeFromName from '../util/iconTypeFromName'
App.controller(
'FileTreeEntityController',
function ($scope, ide, $modal, $element) {
$scope.MAX_DEPTH = 8
$scope.select = function (e) {
if (e.ctrlKey || e.metaKey) {
e.stopPropagation()
const initialMultiSelectCount = ide.fileTreeManager.multiSelectedCount()
ide.fileTreeManager.toggleMultiSelectEntity($scope.entity)
if (initialMultiSelectCount === 0) {
// On first multi selection, also include the current active/open file.
return ide.fileTreeManager.multiSelectSelectedEntity()
}
} else {
ide.fileTreeManager.selectEntity($scope.entity)
return $scope.$emit('entity:selected', $scope.entity)
}
}
if ($scope.entity.type === 'doc') {
$scope.$watch('entity.selected', function (isSelected) {
if (isSelected) {
$scope.$emit('entity-file:selected', $scope.entity)
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.iconTypeFromName = iconTypeFromName
}
)