Skip to content

Commit

Permalink
Layer Control: Scroll position to selected element (#2143)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao authored Oct 10, 2023
1 parent 41082b9 commit 26c161a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ui/src/editor-core/layer-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,48 @@ LayerManager.prototype.render = function(reset) {

this.firstRender = false;
}

// Scroll to selected
self.scrollToSelected();
});
};

/**
* Scroll to selected item
*/
LayerManager.prototype.scrollToSelected = function() {
const self = this;
const $selectedItem = self.DOMObject.find('.selected');

// Render to selected
if ($selectedItem.length > 0) {
// Check if the element is outside the render view
const $layerManagerContainer =
self.DOMObject.find('.layer-manager-body');
const headerHeight = $('.layer-manager-header').height();
const viewHeight = $layerManagerContainer.height();

const elemHeight = $selectedItem.height();
const elemTop = $selectedItem.position().top - headerHeight;
const elemBottom = elemTop + $selectedItem.height();

const isVisible =
(elemTop + elemHeight <= viewHeight) &&
(elemBottom >= elemHeight);

if (!isVisible) {
const scrollAdjust =
(elemTop + elemHeight > viewHeight) ?
((elemTop + elemHeight) - viewHeight) :
(elemBottom - elemHeight);

// Scroll to element ( using deltas )
const viewTop = $layerManagerContainer.scrollTop();
$layerManagerContainer.scrollTop(
viewTop + scrollAdjust,
);
}
}
};

module.exports = LayerManager;

0 comments on commit 26c161a

Please sign in to comment.