From 933d1aca028b25434d2e95c7fbf6af71464d99dc Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Sun, 6 Mar 2016 19:31:37 -0500 Subject: [PATCH] fix jwilkes/purr-data#19: many lines of text inside an Object Box can mess up the GUI viewport * check when the user types "Enter" in an object or message box, and grown the svg viewBox if necessary This should close the corresponding bug --- pd/nw/pd_canvas.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index 25d8bba6c..5bd26a695 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -166,12 +166,16 @@ var canvas_events = (function() { }, grow_svg_for_element= function(elem) { // See if an element overflows the svg bbox, and - // enlarge the svg to accommodate it + // enlarge the svg to accommodate it. + // Note: window.scrollX and window.scrollY might not work + // with Android Chrome 43 and IE. var svg = document.getElementById("patchsvg"), elem_bbox = elem.getBoundingClientRect(), svg_viewbox = svg.getAttribute("viewBox").split(" "), - w = Math.max(elem_bbox.left + elem_bbox.width, svg_viewbox[2]), - h = Math.max(elem_bbox.top + elem_bbox.height, svg_viewbox[3]); + w = Math.max(elem_bbox.left + elem_bbox.width + window.scrollX, + svg_viewbox[2]), + h = Math.max(elem_bbox.top + elem_bbox.height + window.scrollY, + svg_viewbox[3]); svg.setAttribute("viewBox", [Math.min(elem_bbox.left, svg_viewbox[0]), Math.min(elem_bbox.top, svg_viewbox[1]), @@ -433,6 +437,10 @@ var canvas_events = (function() { }, text_keyup: function(evt) { evt.stopPropagation(); + if (evt.keyCode === 13) { + pdgui.post("growing the svg..."); + grow_svg_for_element(textbox()); + } //evt.preventDefault(); return false; }, -- GitLab