8000 feature #21238 [VarDumper] Add search keyboard shortcuts (ogizanagi) · symfony/symfony@1e10227 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e10227

Browse files
committed
feature #21238 [VarDumper] Add search keyboard shortcuts (ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [VarDumper] Add search keyboard shortcuts | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21174 | License | MIT | Doc PR | Worth to mention? So, this PR simply adds the following shortcuts to navigate between matches, based on main browsers conventions: - <kbd>CTRL/CMD</kbd> + (<kbd>shift</kbd>* +) <kbd>G</kbd> - (<kbd>shift</kbd>* +) <kbd>ENTER</kbd> - (<kbd>shift</kbd>* +) <kbd>F3</kbd> _* <kbd>shift</kbd> allows to go backwards_ At first, I wanted to add a help box somewhere, but: - I don't know where to place it. As the var dumper is now used everywhere in the profiler, it should not be importune and should work in narrowed places. - We use those shortcuts in order to replicate the main softwares/browsers behavior. So we may not need it at all. This PR also fixes a minor issue where pressing a key not changing the input would have restarted the search query. Commits ------- 58fe431 [VarDumper] Add search keyboard shortcuts
2 parents da1b082 + 58fe431 commit 1e10227

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,19 +487,20 @@ function showCurrent(state)
487487
var searchInput = search.querySelector('.sf-dump-search-input');
488488
var counter = search.querySelector('.sf-dump-search-count');
489489
var searchInputTimer = 0;
490+
var previousSearchQuery = '';
490491
491-
addEventListener(searchInput, 'keydown', function (e) {
492-
/* Don't intercept escape key in order to not start a search */
493-
if (27 === e.keyCode) {
492+
addEventListener(searchInput, 'keyup', function (e) {
493+
var searchQuery = e.target.value;
494+
/* Don't perform anything if the pressed key didn't change the query */
495+
if (searchQuery === previousSearchQuery) {
494496
return;
495497
}
496-
498+
previousSearchQuery = searchQuery;
497499
clearTimeout(searchInputTimer);
498500
searchInputTimer = setTimeout(function () {
499501
state.reset();
500502
collapseAll(root);
501503
resetHighlightedNodes(root);
502-
var searchQuery = e.target.value;
503504
if ('' === searchQuery) {
504505
counter.textContent = '0 of 0';
505506
@@ -526,17 +527,29 @@ function showCurrent(state)
526527
});
527528
528529
addEventListener(root, 'keydown', function (e) {
529-
if (114 === e.keyCode || (isCtrlKey(e) && 70 === e.keyCode)) {
530-
/* CTRL + F or CMD + F */
530+
var isSearchActive = !/\bsf-dump-search-hidden\b/.test(search.className);
531+
if ((114 === e.keyCode && !isSearchActive) || (isCtrlKey(e) && 70 === e.keyCode)) {
532+
/* F3 or CMD/CTRL + F */
531533
e.preventDefault();
532534
search.className = search.className.replace(/\bsf-dump-search-hidden\b/, '');
533535
searchInput.focus();
534-
} else if (27 === e.keyCode && !/\bsf-dump-search-hidden\b/.test(search.className)) {
535-
/* ESC key */
536-
search.className += ' sf-dump-search-hidden';
537-
e.preventDefault();
538-
resetHighlightedNodes(root);
539-
searchInput.value = '';
536+
} else if (isSearchActive) {
537+
if (27 === e.keyCode) {
538+
/* ESC key */
539+
search.className += ' sf-dump-search-hidden';
540+
e.preventDefault();
541+
resetHighlightedNodes(root);
542+
searchInput.value = '';
543+
} else if (
544+
(isCtrlKey(e) && 71 === e.keyCode) /* CMD/CTRL + G */
545+
|| 13 === e.keyCode /* Enter */
546+
|| 114 === e.keyCode /* F3 */
547+
) {
548+
e.preventDefault();
549+
e.shiftKey ? state.previous() : state.next();
550+
collapseAll(root);
551+
showCurrent(state);
552+
}
540553
}
541554
});
542555
}

0 commit comments

Comments
 (0)
0