8295800d611b301861e0b6e8597e856ae96abf78
chmalee
  Mon Nov 24 16:19:31 2025 -0800
successful HGVS searches get saved into the 'recent searches' dropdown on hgTracks. the position box tries to suggest hgvs when the search term is longer than 8 characters, otherwise we assume it's a gene, refs #35984

diff --git src/hg/js/autocomplete.js src/hg/js/autocomplete.js
index bca7a215600..f5da6076455 100644
--- src/hg/js/autocomplete.js
+++ src/hg/js/autocomplete.js
@@ -26,48 +26,71 @@
                         // sort the results list according to the stack order:
                         let entries = Object.entries(searchObj[currDb].results);
                         let stack = searchObj[currDb].stack;
                         let callbackData = [];
                         for (let s of stack) {
                             callbackData.push(searchObj[currDb].results[s]);
                         }
                         callback(callbackData);
                     }
                     return;
                 } else {
                     return;
                 }
             }
             if (!cache[key]) {
+                if (key.length < 8) {
+                    // probably a gene name
                     $.ajax({
                         url: "../cgi-bin/hgSuggest",
                         data: "db=" + db + "&prefix=" + encodeURIComponent(key),
                         // dataType: "json",  // XXXX this doesn't work under IE, so we retrieve as text and do an eval to force to an object.
                         trueSuccess: function(response, status) {
                             // We get a lot of duplicate requests (especially the first letters of words),
                             // so we keep a cache of the suggestions lists we've retreived.
                             cache[this.key] = response;
                             this.cont(JSON.parse(response));
                         },
                         success: catchErrorOrDispatch,
                         error: function(request, status, errorThrown) {
                             // tolerate errors (i.e. don't report them) to avoid spamming people on flaky network connections
                             // with tons of error messages (#8816).
                         },
                         key: key,
                         cont: callback
                     });
+                } else {
+                    // probably an hgvs term?
+                    $.ajax({
+                        url: "../cgi-bin/hgSuggest",
+                        data: "db=" + db + "&prefix=" + encodeURIComponent(key) + "&type=hgvs",
+                        // dataType: "json",  // XXXX this doesn't work under IE, so we retrieve as text and do an eval to force to an object.
+                        trueSuccess: function(response, status) {
+                            // We get a lot of duplicate requests (especially the first letters of words),
+                            // so we keep a cache of the suggestions lists we've retreived.
+                            cache[this.key] = response;
+                            this.cont(JSON.parse(response));
+                        },
+                        success: catchErrorOrDispatch,
+                        error: function(request, status, errorThrown) {
+                            // tolerate errors (i.e. don't report them) to avoid spamming people on flaky network connections
+                            // with tons of error messages (#8816).
+                        },
+                        key: key,
+                        cont: callback
+                    });
+                }
             } else {
                 callback(JSON.parse(cache[key]));
             }
             // warn(request.term);
         };
     },
 
     clearFindMatches: function() {
         // clear any hgFind.matches set by a previous user selection (e.g. when user directly edits the search box)
         if ($('#hgFindMatches').length) $('#hgFindMatches').remove();
     },
 
     updateFindMatches: function(val) {
         // highlight genes choosen from suggest list (#6330)
         if ($('#hgFindMatches').length) $('#hgFindMatches').val(val);
@@ -136,31 +159,32 @@
                         else $(auto).css({
                             maxHeight: 'none',
                             overflow: 'hidden',
                             zIndex: 12
                         });
                         // we need to remove the ui-menu-item class from the informational div
                         // because it is not selectable/focuseable
                         document.querySelectorAll('.autoCompleteInfo').forEach(function(i) {
                             i.classList.remove("ui-menu-item");
                         });
                     }
                 },
                 select: function(event, ui) {
                     lastSelected = ui.item.value;
                     suggestBox.updateFindMatches(ui.item.internalId);
-                    addRecentSearch(db, ui.item.geneSymbol, ui.item);
+                    let key = typeof(ui.item.geneSymbol) !== 'undefined' ? ui.item.geneSymbol : ui.item.value;
+                    addRecentSearch(db, key, ui.item);
                     selectCallback(ui.item);
                     // jQuery('body').css('cursor', 'wait');
                     // document.TrackHeaderForm.submit();
                 }
             });
         }
 
         // I want to set focus to the suggest element, but unforunately that prevents PgUp/PgDn from
         // working, which is a major annoyance.
         if (typeof $(this).autocompletePosInput !== 'undefined') {
             $('#positionInput').on("focus", function() {$(this).autocompletePosInput("search", "");});
         }
         $("#positionInput").on("change", function(event) {
             if (!lastSelected || lastSelected !== $('#positionInput').val()) {
                 // This handles case where user typed or edited something rather than choosing from a suggest list;