@@ -583,6 +583,14 @@ function addToHistory(query) {
583
583
function updateHistoryUI ( ) {
584
584
elements . queryHistoryElm . innerHTML = '' ;
585
585
586
+ if ( state . queryHistory . length === 0 ) {
587
+ const emptyMessage = document . createElement ( 'div' ) ;
588
+ emptyMessage . className = 'query-history-empty' ;
589
+ emptyMessage . textContent = 'No query history yet' ;
590
+ elements . queryHistoryElm . appendChild ( emptyMessage ) ;
591
+ return ;
592
+ }
593
+
586
594
state . queryHistory . forEach ( ( item ) => {
587
595
const historyItem = createHistoryItem ( item ) ;
588
596
elements . queryHistoryElm . appendChild ( historyItem ) ;
@@ -621,7 +629,29 @@ function truncateString(str, maxLength) {
621
629
}
622
630
623
631
function toggleQueryHistory ( ) {
624
- elements . queryHistoryElm . classList . toggle ( 'show' ) ;
632
+ // Don't open history if there are no items
633
+ if ( ! elements . queryHistoryElm . classList . contains ( 'show' ) && state . queryHistory . length === 0 ) {
634
+ showNotification ( 'No query history yet' ) ;
635
+ return ;
636
+ }
637
+
638
+ const historyElement = elements . queryHistoryElm ;
639
+ const isVisible = historyElement . classList . contains ( 'show' ) ;
640
+
641
+ if ( ! isVisible ) {
642
+ // Position the history panel over the editor
643
+ const editorRect = editor . getWrapperElement ( ) . getBoundingClientRect ( ) ;
644
+ historyElement . style . width = `${ editorRect . width - 20 } px` ;
645
+ historyElement . style . top = '10px' ;
646
+ historyElement . style . height = 'auto' ;
647
+ historyElement . style . maxHeight = `${ editorRect . height - 20 } px` ;
648
+ }
649
+
650
+ historyElement . classList . toggle ( 'show' ) ;
651
+ }
652
+
653
+ function closeQueryHistory ( ) {
654
+ elements . queryHistoryElm . classList . remove ( 'show' ) ;
625
655
}
626
656
627
657
// Toggle history button
@@ -632,7 +662,21 @@ document.addEventListener('click', function(e) {
632
662
if ( elements . queryHistoryElm . classList . contains ( 'show' ) &&
633
663
! elements . queryHistoryElm . contains ( e . target ) &&
634
664
e . target !== elements . toggleHistoryBtn ) {
635
- elements . queryHistoryElm . classList . remove ( 'show' ) ;
665
+ closeQueryHistory ( ) ;
666
+ }
667
+ } ) ;
668
+
669
+ // Close history when pressing Escape
670
+ document . addEventListener ( 'keydown' , function ( e ) {
671
+ if ( e . key === 'Escape' && elements . queryHistoryElm . classList . contains ( 'show' ) ) {
672
+ closeQueryHistory ( ) ;
673
+ }
674
+ } ) ;
675
+
676
+ // Close history when editing code
677
+ editor . on ( 'change' , function ( ) {
678
+ if ( elements . queryHistoryElm . classList . contains ( 'show' ) ) {
679
+ closeQueryHistory ( ) ;
636
680
}
637
681
} ) ;
638
682
0 commit comments