From 8beffc6c33dbd1ba8db85d53b16785da0e415b73 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Thu, 24 Sep 2015 14:53:29 -0700 Subject: [PATCH] Fix dropdowns on scrolled pages. Issue 183. --- blockly_compressed.js | 6 +++--- core/field_dropdown.js | 2 +- core/widgetdiv.js | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 135bb7750..2937a552a 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1166,7 +1166,7 @@ void 0!==b&&(a=b)}null!==a&&g.setValue(a)})};Blockly.FieldColour.widgetDispose_= Blockly.FieldDropdown.prototype.init=function(a){this.sourceBlock_||(this.arrow_=Blockly.createSvgElement("tspan",{},null),this.arrow_.appendChild(document.createTextNode(a.RTL?Blockly.FieldDropdown.ARROW_CHAR+" ":" "+Blockly.FieldDropdown.ARROW_CHAR)),Blockly.FieldDropdown.superClass_.init.call(this,a),a=this.text_,this.text_=null,this.setText(a))}; Blockly.FieldDropdown.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,null);var a=this,b=new goog.ui.Menu;b.setRightToLeft(this.sourceBlock_.RTL);for(var c=this.getOptions_(),d=0;d=c.height+d.y?e.y-h.height:e.y+f.height;this.sourceBlock_.RTL?(e.x+=f.width,e.x+=Blockly.FieldDropdown.CHECKMARK_OVERHANG,e.xc.width+d.x-h.width&&(e.x=c.width+d.x-h.width));Blockly.WidgetDiv.position(e.x,e.y,c,d,this.sourceBlock_.RTL);b.setAllowAutoFocus(!0); +b.render(Blockly.WidgetDiv.DIV);var g=b.getElement();Blockly.addClass_(g,"blocklyDropdownMenu");var h=goog.style.getSize(g);h.height=g.scrollHeight;e.y=e.y+h.height+f.height>=c.height+d.y?e.y-(h.height+2):e.y+f.height;this.sourceBlock_.RTL?(e.x+=f.width,e.x+=Blockly.FieldDropdown.CHECKMARK_OVERHANG,e.xc.width+d.x-h.width&&(e.x=c.width+d.x-h.width));Blockly.WidgetDiv.position(e.x,e.y,c,d,this.sourceBlock_.RTL);b.setAllowAutoFocus(!0); g.focus()}; Blockly.FieldDropdown.prototype.trimOptions_=function(){this.suffixField=this.prefixField=null;var a=this.menuGenerator_;if(goog.isArray(a)&&!(2>a.length)){var b=a.map(function(a){return a[0]}),c=Blockly.shortestStringLength(b),d=Blockly.commonWordPrefix(b,c),e=Blockly.commonWordSuffix(b,c);if((d||e)&&!(c<=d+e)){d&&(this.prefixField=b[0].substring(0,d-1));e&&(this.suffixField=b[0].substr(1-e));b=[];for(c=0;cc.width+d.x&&(a=c.width+d.x):ac.width+d.x&&(a=c.width+d.x):a= windowSize.height + scrollOffset.y) { - xy.y -= menuSize.height; + xy.y -= menuSize.height + 2; } else { xy.y += borderBBox.height; } diff --git a/core/widgetdiv.js b/core/widgetdiv.js index 57aff0878..36eb916b7 100644 --- a/core/widgetdiv.js +++ b/core/widgetdiv.js @@ -87,6 +87,7 @@ Blockly.WidgetDiv.hide = function() { Blockly.WidgetDiv.DIV.style.display = 'none'; Blockly.WidgetDiv.DIV.style.left = ''; Blockly.WidgetDiv.DIV.style.top = ''; + Blockly.WidgetDiv.DIV.style.height = ''; Blockly.WidgetDiv.dispose_ && Blockly.WidgetDiv.dispose_(); Blockly.WidgetDiv.owner_ = null; Blockly.WidgetDiv.dispose_ = null; @@ -129,7 +130,7 @@ Blockly.WidgetDiv.position = function(anchorX, anchorY, windowSize, anchorY = scrollOffset.y; } if (rtl) { - // Don't let the menu go right of the right edge of the window. + // Don't let the widget go right of the right edge of the window. if (anchorX > windowSize.width + scrollOffset.x) { anchorX = windowSize.width + scrollOffset.x; } @@ -141,5 +142,6 @@ Blockly.WidgetDiv.position = function(anchorX, anchorY, windowSize, } Blockly.WidgetDiv.DIV.style.left = anchorX + 'px'; Blockly.WidgetDiv.DIV.style.top = anchorY + 'px'; - Blockly.WidgetDiv.DIV.style.height = windowSize.height - anchorY + 'px'; + Blockly.WidgetDiv.DIV.style.height = + (windowSize.height - anchorY + scrollOffset.y) + 'px'; };