Skip to content

Commit

Permalink
Allow text selection in flamegraph view. (#874)
Browse files Browse the repository at this point in the history
Previously, the click handler would fire after some text was selected
with the mouse. This would switch pivots and forget the selected text.

We now switch the pivot only if the mouse did not move significantly
between mouse-down and mouse-up.

Fixes #870.
  • Loading branch information
ghemawat authored Jun 25, 2024
1 parent c177fd9 commit 27f5697
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/driver/html/stacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 27f5697

Please sign in to comment.