eddcc31f5787c57ae35557080913eb2ca74dfdb1
max
  Thu Mar 2 11:29:03 2017 -0800
adding keyboard shortcuts ma/mc/mn and also one more button to the highlight dialog, refs #18936

diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index 3a861e4..5bf56bc 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -985,38 +985,47 @@
     },
 
     selectChange: function (img, selection)
     {
         if (selection.x1 !== selection.x2) {
             if (genomePos.check(img, selection)) {
                 genomePos.update(img, selection, false);
                 jQuery('body').css('cursor', dragSelect.originalCursor);
             } else {
                 jQuery('body').css('cursor', 'not-allowed');
             }
         }
         return true;
     },
 
-    highlightThisRegion: function(newPosition)
+    highlightThisRegion: function(newPosition, doAdd)
     // set highlighting newPosition in server-side cart and apply the highlighting in local UI.
     {
         var pos = parsePosition(newPosition);
         var start = pos.start;
         var end = pos.end;
-        hgTracks.highlight = getDb() + "." + pos.chrom + ":" + start + "-" + end + '#AAFFFF';
-        hgTracks.highlight = imageV2.disguiseHighlight(hgTracks.highlight);
+        var newHighlight = getDb() + "." + pos.chrom + ":" + start + "-" + end + '#77cccc';
+        newHighlight = imageV2.disguiseHighlight(newHighlight);
+        var oldHighlight = hgTracks.highlight;
+        if (doAdd===undefined || doAdd===false || oldHighlight==="") {
+            // overwrite the old highlight position
+            hgTracks.highlight = newHighlight;
+        }
+        else {
+            // add to the end of a |-separated list
+            hgTracks.highlight = oldHighlight+"|"+newHighlight;
+        }
         // we include enableHighlightingDialog because it may have been changed by the dialog
         var cartSettings = {             'highlight': hgTracks.highlight, 
                           'enableHighlightingDialog': hgTracks.enableHighlightingDialog ? 1 : 0 };
 
         if (hgTracks.windows && !hgTracks.virtualSingleChrom) {
             var nonVirtChrom = "";
             var nonVirtStart = -1; 
             var nonVirtEnd   = -1; 
             for (i=0,len=hgTracks.windows.length; i < len; ++i) {
                 var w = hgTracks.windows[i];
                 // overlap with new position?
                 if (w.virtEnd > start && end > w.virtStart) {
                     var s = Math.max(start, w.virtStart);
                     var e = Math.min(end, w.virtEnd);
                     var cs = s - w.virtStart + w.winStart;
@@ -1083,59 +1092,66 @@
             str2 += "</ul>\n";
             if (!(hgTracks.virtualSingleChrom && (selectedRegions === 1))) {
                 str += str2;
             }
             $("#dragSelectPosition").html(str);
         } else {
             $("#dragSelectPosition").html(newPosition);
         }
         $(dragSelectDialog).dialog({
                 modal: true,
                 title: "Drag-and-select",
                 closeOnEscape: true,
                 resizable: false,
                 autoOpen: false,
                 revertToOriginalPos: true,
-                minWidth: 400,
+                minWidth: 450,
                 buttons: {  
                     "Zoom In": function() {
                         // Zoom to selection
                         $(this).dialog("option", "revertToOriginalPos", false);
                         if ($("#disableDragHighlight").attr('checked'))
                             hgTracks.enableHighlightingDialog = false;
                         if (imageV2.inPlaceUpdate) {
                             if (hgTracks.virtualSingleChrom && (newPosition.search("virt:")===0)) {
                                 newPosition = genomePos.disguisePosition(newPosition); // DISGUISE
                             }
                             var params = "position=" + newPosition;
                             if (!hgTracks.enableHighlightingDialog)
                                 params += "&enableHighlightingDialog=0";
                             imageV2.navigateInPlace(params, null, true);
                         } else {
                             $('body').css('cursor', 'wait');
                             if (!hgTracks.enableHighlightingDialog)
                                 cart.setVarsObj({'enableHighlightingDialog': 0 },null,false); // async=false
                             document.TrackHeaderForm.submit();
                         }
                         $(this).dialog("close");
                     },
-                    "Highlight": function() {
-                        // Highlight selection
+                    "New Highlight": function() {
+                        // Clear old highlight and Highlight selection
                         $(imageV2.imgTbl).imgAreaSelect({hide:true});
                         if ($("#disableDragHighlight").attr('checked'))
                             hgTracks.enableHighlightingDialog = false;
-                        dragSelect.highlightThisRegion(newPosition);
+                        dragSelect.highlightThisRegion(newPosition, false);
+                        $(this).dialog("close");
+                    },
+                    "Add Highlight": function() {
+                        // Highlight selection
+                        if ($("#disableDragHighlight").attr('checked'))
+                            hgTracks.enableHighlightingDialog = false;
+                        dragSelect.highlightThisRegion(newPosition, true);
                         $(this).dialog("close");
                     },
                     "Cancel": function() {
                         $(this).dialog("close");
                     }
                 },
 
                 open: function () { // Make zoom the focus/default action
                    $(this).parents('.ui-dialog-buttonpane button:eq(0)').focus(); 
                 },
 
                 close: function() {
                     // All exits to dialog should go through this
                     $(imageV2.imgTbl).imgAreaSelect({hide:true});
                     if ($(this).dialog("option", "revertToOriginalPos"))
@@ -3354,30 +3370,45 @@
 }
 
 // A function for the keyboard shortcuts "zoom to x bp"
 function zoomTo(zoomSize) {
     var flankSize = Math.floor(zoomSize/2);
     var pos = parsePosition(genomePos.get());
     var mid = pos.start+(Math.floor((pos.end-pos.start)/2));
     var newStart = Math.max(mid - flankSize, 0);
     var newEnd = mid + flankSize - 1;
     var newPos = genomePos.setByCoordinates(pos.chrom, newStart, newEnd);
     if (hgTracks.virtualSingleChrom && (newPos.search("virt:")===0))
         newPos = genomePos.disguisePosition(newPosition); // DISGUISE?
     imageV2.navigateInPlace("position="+newPos, null, true);
 }
 
+// A function for the keyboard shortcuts "highlight add/clear/new"
+function highlightCurrentPosition(mode) {
+    var pos = genomePos.get();
+    if (mode=="new")
+        dragSelect.highlightThisRegion(pos, false);
+    else if (mode=="add")
+        dragSelect.highlightThisRegion(pos, true);
+    else {
+        hgTracks.highlight = "";
+        var cartSettings = {'highlight': ""};
+        cart.setVarsObj(cartSettings);
+        imageV2.highlightRegion();
+    }
+}
+
   //////////////////////////////////
  //// popup (aka modal dialog) ////
 //////////////////////////////////
 var popUp = {
 
     trackName:            "",
     trackDescriptionOnly: false,
     saveAllVars:          null,
 
     cleanup: function ()
     {  // Clean out the popup box on close
         if ($('#hgTrackUiDialog').html().length > 0 ) {
             // clear out html after close to prevent problems caused by duplicate html elements
             $('#hgTrackUiDialog').html("");
             popUp.trackName = ""; //set to defaults