@@ -258,7 +258,7 @@ class Model {
258258 this . savedHistory . clear ( ) ;
259259 }
260260 addToHistory ( ) {
261- this . savedHistory . add ( { query : this . editor . value , name : this . queryName , useToolingApi : this . queryTooling } ) ;
261+ this . savedHistory . add ( { query : this . editor . value , name : this . queryName , useToolingApi : this . queryTooling , tags : [ ] } ) ;
262262 }
263263 removeFromHistory ( ) {
264264 this . savedHistory . remove ( { query : this . editor . value , name : this . queryName , useToolingApi : this . queryTooling } ) ;
@@ -2071,19 +2071,19 @@ class Model {
20712071 //TODO query: this.editor.value, name: this.queryName, useToolingApi: this.queryTooling
20722072 getHistory ( ) {
20732073 let historyMap = new Map ( ) ;
2074- this . queryHistory . list . forEach ( q => historyMap . set ( q . query , { value : q . query , label : q . query . substring ( 0 , 300 ) , favorite : false , useToolingApi : q . useToolingApi } ) ) ;
2074+ this . queryHistory . list . forEach ( q => historyMap . set ( q . query , { value : q . query , label : q . query . substring ( 0 , 300 ) , favorite : false , useToolingApi : q . useToolingApi , tags : q . tags || [ ] } ) ) ;
20752075 this . queryTemplates . forEach ( q => historyMap . set ( q , { value : q , label : q , favorite : true , useToolingApi : false } ) ) ;
20762076 this . savedHistory . list . forEach ( q => {
20772077 let delimiter = ":" ;
20782078 let itm ;
20792079 if ( q . name ) {
2080- itm = { value : q . query , label : q . name , name : q . name , favorite : true , useToolingApi : q . useToolingApi } ;
2080+ itm = { value : q . query , label : q . name , name : q . name , favorite : true , useToolingApi : q . useToolingApi , tags : q . tags || [ ] } ;
20812081 } else if ( q . query . includes ( delimiter ) ) {
2082- itm = { label : q . query . split ( delimiter ) [ 0 ] , favorite : true , useToolingApi : q . useToolingApi } ;
2082+ itm = { label : q . query . split ( delimiter ) [ 0 ] , favorite : true , useToolingApi : q . useToolingApi , tags : q . tags || [ ] } ;
20832083 itm . name = itm . label ;
20842084 itm . value = q . query . substring ( itm . label . length + 1 ) ;
20852085 } else {
2086- itm = { value : q . query , label : q . query , favorite : true , useToolingApi : q . useToolingApi } ;
2086+ itm = { value : q . query , label : q . query , favorite : true , useToolingApi : q . useToolingApi , tags : q . tags || [ ] } ;
20872087 }
20882088 historyMap . set ( itm . value , itm ) ;
20892089 } ) ;
@@ -2109,13 +2109,22 @@ class Model {
21092109 }
21102110 updateHistoryItem ( history ) {
21112111 if ( history . favorite ) {
2112- let itm = this . queryHistory . list . find ( item => ( item . query == history . value ) && ( item . useToolingApi == history . useToolingApi ) ) ;
2112+ // For saved queries (favorites), find and update in savedHistory
2113+ // Match by query value and useToolingApi (name might be changing, so don't match by name)
2114+ let itm = this . savedHistory . list . find ( item =>
2115+ item . query == history . value && item . useToolingApi == history . useToolingApi
2116+ ) ;
21132117 if ( itm ) {
2114- this . queryHistory . remove ( itm ) ;
2118+ // Use tags from history if provided, otherwise preserve existing tags
2119+ const tagsToUse = Array . isArray ( history . tags ) ? history . tags : ( itm . tags || [ ] ) ;
2120+ // Remove old entry
2121+ this . savedHistory . remove ( itm ) ;
2122+ // Add updated entry with new name and tags
2123+ let newSaved = { query : history . value , useToolingApi : history . useToolingApi ?? false , name : history . name , tags : tagsToUse } ;
2124+ this . savedHistory . add ( newSaved ) ;
21152125 }
2116- let newSaved = { query : history . value , useToolingApi : history . useToolingApi ?? false } ;
2117- this . savedHistory . add ( newSaved ) ;
21182126 } else {
2127+ // For regular history items, check if they're in savedHistory first
21192128 let itm = this . savedHistory . list . find ( item => ( item . useToolingApi == history . useToolingApi && ( ( item . query == history . value && item . name && item . name == history . label ) || ( item . query == history . label + ":" + history . value ) || ( item . query == history . value && item . query == history . label ) ) ) ) ;
21202129 if ( itm ) {
21212130 this . savedHistory . remove ( itm ) ;
@@ -2126,10 +2135,18 @@ class Model {
21262135 localStorage . setItem ( "queryTemplates" , JSON . stringify ( this . queryTemplates ) ) ;
21272136 }
21282137 }
2138+ // Find existing history item to preserve tags
2139+ let existingHistory = this . queryHistory . list . find ( item => item . query == history . value && item . useToolingApi == history . useToolingApi ) ;
21292140 let newHistory = { query : history . value , useToolingApi : history . useToolingApi } ;
21302141 if ( itm && itm . name ) {
21312142 newHistory . name = itm . name ;
21322143 }
2144+ // Preserve tags from history object or existing history item
2145+ if ( Array . isArray ( history . tags ) && history . tags . length > 0 ) {
2146+ newHistory . tags = history . tags ;
2147+ } else if ( existingHistory && existingHistory . tags ) {
2148+ newHistory . tags = existingHistory . tags ;
2149+ }
21332150 this . queryHistory . add ( newHistory ) ;
21342151 }
21352152 }
0 commit comments