From aec47653420eb35fb84d437ec310097a9d873790 Mon Sep 17 00:00:00 2001
From: Albert Graef <aggraef@gmail.com>
Date: Sat, 13 Aug 2022 01:03:19 +0200
Subject: [PATCH] Keep editing after clicking an item in the autocomplete
 dropdown.

Previously this would cause the object to be instantiated immediately,
without giving the user a chance to enter arguments. Now this action is
handled in exactly the same manner as completions initiated with the Tab
and Return keys.
---
 pd/nw/pd_canvas.js | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js
index 1e37754ec..c67ce9201 100644
--- a/pd/nw/pd_canvas.js
+++ b/pd/nw/pd_canvas.js
@@ -520,6 +520,17 @@ var canvas_events = (function() {
             text_mousedown: function(evt) {
                 if (evt.target.parentNode === document.getElementById("autocomplete_dropdown")) {
                     pdgui.select_result_autocomplete_dd(textbox(), document.getElementById("autocomplete_dropdown"));
+                    // ag: Don't do the usual object instantiation thing if
+                    // we've clicked on the autocompletion dropdown. This
+                    // means that the user can just go on editing, entering
+                    // object arguments, etc.
+                    evt.stopPropagation();
+                    //evt.preventDefault();
+                    caret_end();
+                    // Defer this to the event loop to prevent losing the
+                    // keyboard focus.
+                    setTimeout(function () { textbox().focus() }, 0);
+                    return false;
                 }
                 if (textbox() !== evt.target && !target_is_scrollbar(evt)) {
                     utils.create_obj();
@@ -569,9 +580,8 @@ var canvas_events = (function() {
                         } else { // else, if there is a selected item on autocompletion tool, the selected item is written on the box
                             pdgui.select_result_autocomplete_dd(textbox(), ac_dropdown());
                             caret_end();
-                            // TODO: Substitute the editing box by the object itself
-                            // utils.create_obj(); // not working, it's not that simple.
-                            // canvas_events.normal();
+                            // No need to instantiate the object here,
+                            // presumably the user wants to go on editing.
                         }
                         break;
                     case 9: // tab
-- 
GitLab