85de86d688b23d0663ee6c4e3376fe6708148550
chmalee
  Mon Nov 28 09:55:49 2022 -0800
Forgot to check for an empty search string when deciding whether to go from hgGateway to hgSearch/hgTracks

diff --git src/hg/js/hgGateway.js src/hg/js/hgGateway.js
index 2baec38..a84584e 100644
--- src/hg/js/hgGateway.js
+++ src/hg/js/hgGateway.js
@@ -1496,70 +1496,72 @@
             cart.send(cmd, handleSetDb);
             cart.flush();
             uiState.db = db;
             clearPositionInput();
         }
     }
 
     function onClickCopyPosition() {
         // Copy the displayed position into the position input:
         var posDisplay = $('#positionDisplay').text();
         $('#positionInput').val(posDisplay).focus();
     }
 
     function goToHgTracks() {
         // Create and submit a form for hgTracks with hidden inputs for org, db and position.
+        var goDirectlyToHgTracks = false;
         var position = $('#positionInput').val();
         var searchTerm = encodeURIComponent(position);
         var posDisplay = $('#positionDisplay').text();
         var pix = uiState.pix || calculateHgTracksWidth();
         var oldCgi = cart.cgi();
         cart.setCgi('hgSearch');
+        if (! position || position === '' || position === positionWatermark ||
+            position === selectedGene) {
+            position = posDisplay;
+            goDirectlyToHgTracks = true;
+        } else {
+            position = position.replace(/\u2013|\u2014/g, "-");  // replace en-dash and em-dash with hyphen
+        }
         var $form;
         $form = $('<form action="hgTracks" method=GET id="mainForm">' +
                   '<input type=hidden name="hgsid" value="' + window.hgsid + '">' +
                   '<input type=hidden name="org" value="' + uiState.genome + '">' +
                   '<input type=hidden name="db" value="' + uiState.db + '">' +
                   '<input type=hidden name="position" value="' + position + '">' +
                   '<input type=hidden name="pix" value="' + pix + '">' +
                   '</form>');
-        if (! position || position === '' || position === positionWatermark ||
-            position === selectedGene) {
-            position = posDisplay;
-        } else {
-            position = position.replace(/\u2013|\u2014/g, "-");  // replace en-dash and em-dash with hyphen
-        }
         // helper functions for checking whether a plain chrom name was searched for
         function onSuccess(jqXHR, textStatus) {
             if (jqXHR.chromName !== null) {
                 $('body').append($form);
                 $form.submit();
             } else  {
                 window.location.assign("../cgi-bin/hgSearch?search=" + searchTerm  + "&hgsid="+ window.hgsid );
             }
         }
         function onFail(jqXHR, textStatus) {
             window.location.assign("../cgi-bin/hgSearch?search=" + searchTerm  + "&hgsid="+ window.hgsid );
         }
         var canonMatch = position.match(canonicalRangeExp);
         var gbrowserMatch = position.match(gbrowserRangeExp);
         var lengthMatch = position.match(lengthRangeExp);
         var bedMatch = position.match(bedRangeExp);
         var sqlMatch = position.match(sqlRangeExp);
         var singleMatch = position.match(singleBaseExp);
         var positionMatch = canonMatch || gbrowserMatch || lengthMatch || bedMatch || sqlMatch || singleMatch;
-        if (positionMatch !== null) {
+        if (positionMatch !== null || goDirectlyToHgTracks) {
             // We already have a position from either selecting a suggestion or the user just typed a regular
             // old position, so go to hgTracks at that location
             // Show a spinner -- sometimes it takes a while for hgTracks to start displaying.
             $('.jwGoIcon').removeClass('fa-play').addClass('fa-spinner fa-spin');
             // Make a form and submit it.  In order for this to work in IE, the form
             // must be appended to the body.
             $('body').append($form);
             $form.submit();
         } else {
             // User has entered a search term with no suggestion, go to the disambiguation
             // page so the user can choose a position
             // but first check if just a plain chromosome name was entered:
             $('.jwGoIcon').removeClass('fa-play').addClass('fa-spinner fa-spin');
             cmd = {getChromName: {'searchTerm': searchTerm, 'db': uiState.db}};
             cart.send(cmd, onSuccess, onFail);