Merge pull request from ericrosenbaum/bugfix/scroll-position-stability

Support for scroll position stability
This commit is contained in:
Eric Rosenbaum 2018-03-15 15:18:54 -04:00 committed by GitHub
commit d60e700c3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 0 deletions

View file

@ -590,6 +590,24 @@ Blockly.Flyout.prototype.stepScrollAnimation = function() {
requestAnimationFrame(this.stepScrollAnimation.bind(this));
};
/**
* Get the scaled scroll position.
* @return {number} The current scroll position.
*/
Blockly.Flyout.prototype.getScrollPos = function() {
var pos = this.horizontalLayout_ ?
-this.workspace_.scrollX : -this.workspace_.scrollY;
return pos / this.workspace_.scale;
};
/**
* Set the scroll position, scaling it.
* @param {number} pos The scroll position to set.
*/
Blockly.Flyout.prototype.setScrollPos = function(pos) {
this.scrollbar_.set(pos * this.workspace_.scale);
};
/**
* Delete blocks and background buttons from a previous showing of the flyout.
* @private

View file

@ -337,6 +337,45 @@ Blockly.Toolbox.prototype.getSelectedItem = function() {
return this.selectedItem_;
};
/**
* @return {string} The name of the currently selected category.
*/
Blockly.Toolbox.prototype.getSelectedCategoryName = function() {
return this.selectedItem_.name_;
};
/**
* @return {number} The distance flyout is scrolled below the top of the currently
* selected category.
*/
Blockly.Toolbox.prototype.getCategoryScrollOffset = function() {
var categoryPos = this.getCategoryPositionByName(this.getSelectedCategoryName());
return this.flyout_.getScrollPos() - categoryPos;
};
/**
* Get the position of a category by name.
* @param {string} name The name of the category.
* @return {number} The position of the category.
*/
Blockly.Toolbox.prototype.getCategoryPositionByName = function(name) {
var scrollPositions = this.flyout_.categoryScrollPositions;
for (var i = 0; i < scrollPositions.length; i++) {
if (name === scrollPositions[i].categoryName) {
return scrollPositions[i].position;
}
}
};
/**
* Set the scroll position of the flyout.
* @param {number} pos The position to set.
*/
Blockly.Toolbox.prototype.setFlyoutScrollPos = function(pos) {
this.flyout_.setScrollPos(pos);
};
/**
* Set the currently selected category.
* @param {Blockly.Toolbox.Category} item The category to select.