From 7ad299e709c05d3bedbf815c6f4fde1e1995f445 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Tue, 20 Jun 2017 22:18:55 -0400
Subject: [PATCH] allow scrollbar navigation for the menu, and factor in the
 window's scrollbar height from the maximum menu height

---
 pd/nw/pd_canvas.js | 14 +++++++++++++-
 pd/nw/pdgui.js     |  9 ++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js
index ad1bf2fc8..046617fff 100644
--- a/pd/nw/pd_canvas.js
+++ b/pd/nw/pd_canvas.js
@@ -555,7 +555,19 @@ var canvas_events = (function() {
                 }
             },
             dropdown_menu_mousedown: function(evt) {
-                var select_elem = document.querySelector("#dropdown_list");
+                var select_elem = document.querySelector("#dropdown_list"),
+                    in_dropdown = evt.target;
+                while (in_dropdown) {
+                    if (in_dropdown.id === "dropdown_list") {
+                        break;
+                    }
+                    in_dropdown = in_dropdown.parentNode;
+                }
+                if (in_dropdown &&
+                        evt.pageX - select_elem.offsetLeft >
+                        select_elem.clientWidth) {
+                    return;
+                }
                 if (evt.target.parentNode
                     && evt.target.parentNode.parentNode
                     && evt.target.parentNode.parentNode.id === "dropdown_list") {
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 9b074b430..657ce1218 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -4609,9 +4609,16 @@ function gui_dropdown_activate(cid, obj_tag, tag, current_index, font_size, stat
                 .window.document.querySelector("#dropdown_list");
             // stick the obj_tag in a data field
             select_elem.setAttribute("data-callback", obj_tag);
+            // set the maximum height of the menu to be the remaining
+            // space below the corresponding widget, minus the size of
+            // the scrollbar. (innerHeight includes scrollbar, and
+            // the documentElement's clientHeight (apparently) does not.
             select_elem.style.setProperty("max-height",
                 (patchwin[cid].window.innerHeight -
-                    g.getBoundingClientRect().bottom - 5) + "px"
+                    g.getBoundingClientRect().bottom -
+                    (patchwin[cid].window.innerHeight -
+                    patchwin[cid].window.document.documentElement.clientHeight))
+                    + "px"
             );
             select_elem.style.setProperty("display", "inline");
             select_elem.style.setProperty("left",
-- 
GitLab