Taitava / obsidian-shellcommands

Execute system commands via hotkeys or command palette in Obsidian (https://obsidian.md). Some automated events are also supported, and execution via URI links.
GNU General Public License v3.0
348 stars 11 forks source link

Bug: Autocomplete menu causes some unintended console logging #223

Closed Taitava closed 2 years ago

Taitava commented 2 years ago

0.12.0 contains accidentally my modified version of the autocomplete library. I had done some test modifications that were not supposed to go into a released version of SC. The modifications are not drastic and should cause no harm. A small thing can be noticed in the console log (if you press Ctrl + Shift + I), there might be shown some unintentional test messages after an autocomplete menu has been used.

The modifications were done on keydownEventHandler() method:

       function keydownEventHandler(ev) {
           var keyCode = ev.which || ev.keyCode || 0;
           if (keyCode === 38 /* Up */ || keyCode === 40 /* Down */ || keyCode === 27 /* Esc */) {
               var containerIsDisplayed = containerDisplayed();
               if (keyCode === 27 /* Esc */) {
+                  console.log("Esc was pressed"); // TODO: DO NOT COMMIT!
+                  ev.preventDefault();
+                  ev.stopPropagation();
+                  ev.stopImmediatePropagation();
                   clear();
               }
               else {
                   if (!containerIsDisplayed || items.length < 1) {
                       return;
                   }
                   keyCode === 38 /* Up */
                       ? selectPrev()
                       : selectNext();
                   update();
               }
               ev.preventDefault();
               if (containerIsDisplayed) {
                   ev.stopPropagation();
               }
               return;
           }
           if (keyCode === 13 /* Enter */) {
               if (selected) {
                   settings.onSelect(selected, input);
                   clear();
               }
               if (preventSubmit) {
                   ev.preventDefault();
               }
           }
+          console.log("Closing keys are:"); // TODO: DO NOT COMMIT!
+          console.log(settings.closingKeys); // TODO: DO NOT COMMIT!
+          console.log("Pressed key was: " + keyCode); // TODO: DO NOT COMMIT!
+          if (settings.closingKeys && keyCode in settings.closingKeys) {
+              // Close the menu.
+              clear();
+              console.log("CLOSING"); // TODO: DO NOT COMMIT!
+              ev.stopPropagation();
+              ev.preventDefault();
+          }
       }

I'll release a fix in 0.12.1 that will remove these additional lines. I never actually committed these changes into this this repository, nor into my fork of the autocomplete library, but as I forgot to remove the modifications, they were accidentally included during a build process. This is a good lesson for me to learn to also check any possible changes I might have made in this library, too.

As the unintented changes were not part of any commit, there will also be no fixing commit linked to this issue. The fix will just occur in the released main.js file.

Taitava commented 2 years ago

Fix released.