From f8be333400f0c7217749c42eaf8d9e031947e7ed Mon Sep 17 00:00:00 2001 From: Manoj Dayaram Date: Fri, 13 Jun 2025 15:31:27 -0400 Subject: [PATCH] feat: add ESC key to collapse expanded profiler results When profiler results are expanded, pressing ESC will collapse them back to the summary view. Integrates with existing ESC key handling for popups. --- lib/html/includes.js | 26 +++++++++++++++++++++++++- lib/mini_profiler/asset_version.rb | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/html/includes.js b/lib/html/includes.js index daf252e4..8b0325b0 100644 --- a/lib/html/includes.js +++ b/lib/html/includes.js @@ -214,6 +214,25 @@ var _MiniProfiler = (function() { return tempElement.children[0]; }; + var collapseResults = function collapseResults() { + if (expandedResults && totalsControl && container) { + // Hide all individual results except totals + toArray( + container.querySelectorAll(".profiler-result") + ).forEach(function(el) { + if (el !== totalsControl) { + el.style.display = "none"; + } + }); + + // Show totals control again + totalsControl.style.display = "block"; + + // Reset expanded state + expandedResults = false; + } + }; + var buttonShow = function buttonShow(json) { var result = renderTemplate(json); totalTime += parseFloat(json.duration_milliseconds, 10); @@ -518,7 +537,13 @@ var _MiniProfiler = (function() { } ); + var isEscPress = e.type == "keyup" && e.which == 27; + if (!popup.length) { + // Handle ESC when no popups are open but results are expanded + if (isEscPress && expandedResults) { + collapseResults(); + } return; } @@ -528,7 +553,6 @@ var _MiniProfiler = (function() { ".profiler-queries" ), bg = document.querySelector(".profiler-queries-bg"), - isEscPress = e.type == "keyup" && e.which == 27, hidePopup = false, hideQueries = false; diff --git a/lib/mini_profiler/asset_version.rb b/lib/mini_profiler/asset_version.rb index e640fcb0..5ea56cf0 100644 --- a/lib/mini_profiler/asset_version.rb +++ b/lib/mini_profiler/asset_version.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true module Rack class MiniProfiler - ASSET_VERSION = 'e0bcc9ce0ae3bb5d6b736b6f282f601f' + ASSET_VERSION = '1592fcee961471b6d33bb772925ef913' end end