Move selectCategoryByScrollPosition to flyout_base

This commit is contained in:
Eric Rosenbaum 2017-09-18 16:40:55 -04:00
parent 8e3a4bfce8
commit 89ea480ab0
3 changed files with 17 additions and 32 deletions

View file

@ -552,6 +552,23 @@ Blockly.Flyout.prototype.recordCategoryScrollPositions_ = function() {
}
};
/**
* Select a category using the scroll position.
* @param {number} pos The scroll position.
* @package
*/
Blockly.Flyout.prototype.selectCategoryByScrollPosition = function(pos) {
var scaledPos = pos / this.workspace_.scale;
// Traverse the array of scroll positions in reverse, so we can select the furthest
// category that the scroll position is beyond
for (var i = this.categoryScrollPositions.length - 1; i >= 0; i--) {
if (scaledPos > this.categoryScrollPositions[i].position) {
this.parentToolbox_.selectCategoryByName(this.categoryScrollPositions[i].categoryName);
return;
}
}
};
/**
* Step the scrolling animation by scrolling a fraction of the way to
* a scroll target, and request the next frame if necessary.

View file

@ -306,22 +306,6 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) {
e.stopPropagation();
};
/**
* Select a category using the scroll position
* @param {number} pos The scroll position.
*/
Blockly.HorizontalFlyout.prototype.selectCategoryByScrollPosition = function(pos) {
var scaledPos = pos / this.workspace_.scale;
// Traverse the array of scroll positions in reverse, so we can select the lowest
// category that the scroll position is below
for (var i = this.categoryScrollPositions.length - 1; i >= 0; i--) {
if (scaledPos > this.categoryScrollPositions[i].position) {
this.parentToolbox_.selectCategoryByName(this.categoryScrollPositions[i].categoryName);
return;
}
}
};
/**
* Lay out the blocks in the flyout.
* @param {!Array.<!Object>} contents The blocks and buttons to lay out.

View file

@ -385,22 +385,6 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) {
e.stopPropagation();
};
/**
* Select a category using the scroll position
* @param {number} pos The scroll position.
*/
Blockly.VerticalFlyout.prototype.selectCategoryByScrollPosition = function(pos) {
var scaledPos = pos / this.workspace_.scale;
// Traverse the array of scroll positions in reverse, so we can select the lowest
// category that the scroll position is below
for (var i = this.categoryScrollPositions.length - 1; i >= 0; i--) {
if (scaledPos > this.categoryScrollPositions[i].position) {
this.parentToolbox_.selectCategoryByName(this.categoryScrollPositions[i].categoryName);
return;
}
}
};
/**
* Delete blocks and background buttons from a previous showing of the flyout.
* @private