From de23ce808b37553ac28cca50c3af8416018f9e1a Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Wed, 3 May 2017 16:30:17 -0400
Subject: [PATCH] fix #306: OSX: Zoomed-in behaviour while using cursor keys to
 move an object - the whole screen moves. This fix allows cursor keys in
 runmode while disabling them in editmode.

---
 pd/nw/pd_canvas.js | 8 +++++++-
 pd/nw/pdgui.js     | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js
index ec30c9c3a..cf1cd6805 100644
--- a/pd/nw/pd_canvas.js
+++ b/pd/nw/pd_canvas.js
@@ -304,6 +304,12 @@ var canvas_events = (function() {
             },
             keydown: function(evt) {
                 pdgui.keydown(name, evt);
+                // prevent the default behavior of scrolling
+                // on arrow keys in editmode
+                if (document.querySelector("#patchsvg")
+                    .classList.contains("editmode")) {
+                    evt.preventDefault();
+                }
             },
             keypress: function(evt) {
                 pdgui.keypress(name, evt);
@@ -926,7 +932,7 @@ function register_window_id(cid, attr_array) {
     // Initialize the zoom level to the value retrieved from the patch, if any.
     nw.Window.get().zoomLevel = attr_array.zoom;
     pdgui.canvas_map(cid); // side-effect: triggers gui_canvas_get_scroll
-    pdgui.canvas_set_editmode(cid, attr_array.editmod);
+    pdgui.canvas_set_editmode(cid, attr_array.editmode);
     // For now, there is no way for the cord inspector to be turned on by
     // default. But if this changes we need to set its menu item checkbox
     // accordingly here
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 71cca8438..607b28e79 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -4909,6 +4909,8 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text,
     var range, svg_view, p,
         gobj = get_gobj(cid, tag);
     if (state !== 0) {
+        // Make sure we're in editmode
+        canvas_set_editmode(cid, 1);
         // Hide the gobj while we edit.  However, we want the gobj to
         // contribute to the svg's bbox-- that way when the new_object_textentry
         // goes away we still have the same dimensions.  Otherwise the user
-- 
GitLab