Repository: google/pprof (language: go)

Issue:
New flamegraph cannot copy strings
Please answer these questions before submitting your issue. Thanks!

### What version of pprof are you using?
v0.0.0-20240528025155-186aa0362fba


### What operating system and processor architecture are you using?
Linux  amd64

### What did you do?

Go to flame graph
Highlight text in a cell
Release mouse -- it is deselected, making it impossible to copy


### What did you expect to see?

Text remains selected

Happens on firefox and chrome




Discussion / hints:

Fix patch:
diff --git a/internal/driver/html/stacks.js b/internal/driver/html/stacks.js
index df0f0649..ced7151e 100644
--- a/internal/driver/html/stacks.js
+++ b/internal/driver/html/stacks.js
@@ -436,13 +436,29 @@ function stackViewer(stacks, nodes) {
       r.appendChild(t);
     }
 
-    r.addEventListener('click', () => { switchPivots(pprofQuoteMeta(src.UniqueName)); });
+    onClick(r, () => { switchPivots(pprofQuoteMeta(src.UniqueName)); });
     r.addEventListener('mouseenter', () => { handleEnter(box, r); });
     r.addEventListener('mouseleave', () => { handleLeave(box); });
     r.addEventListener('contextmenu', (e) => { showActionMenu(e, box); });
     return r;
   }
 
+  // Handle clicks, but only if the mouse did not move during the click.
+  function onClick(target, handler) {
+    // Disable click if mouse moves more than threshold pixels since mousedown.
+    const threshold = 3;
+    let [x, y] = [-1, -1];
+    target.addEventListener('mousedown', (e) => {
+      [x, y] = [e.clientX, e.clientY];
+    });
+    target.addEventListener('click', (e) => {
+      if (Math.abs(e.clientX - x) <= threshold &&
+          Math.abs(e.clientY - y) <= threshold) {
+        handler();
+      }
+    });
+  }
+
   function drawSep(y, posTotal, negTotal) {
     const m = document.createElement('div');
     m.innerText = summary(posTotal, negTotal);


Test patch: