@@ -13,6 +13,11 @@ import { QueryHistoryConfig } from './config';
13
13
* `TreeDataProvider` subclass below.
14
14
*/
15
15
16
+ export type QueryHistoryItemOptions = {
17
+ label ?: string , // user-settable label
18
+ queryText ?: string , // stored query for quick query
19
+ }
20
+
16
21
/**
17
22
* One item in the user-displayed list of queries that have been run.
18
23
*/
@@ -25,7 +30,7 @@ export class QueryHistoryItem {
25
30
constructor (
26
31
info : EvaluationInfo ,
27
32
public config : QueryHistoryConfig ,
28
- public label ?: string , // user-settable label
33
+ public options : QueryHistoryItemOptions = info . historyItemOptions ,
29
34
) {
30
35
this . queryName = helpers . getQueryName ( info ) ;
31
36
this . databaseName = info . database . name ;
@@ -65,8 +70,8 @@ export class QueryHistoryItem {
65
70
}
66
71
67
72
getLabel ( ) : string {
68
- if ( this . label !== undefined )
69
- return this . label ;
73
+ if ( this . options . label !== undefined )
74
+ return this . options . label ;
70
75
return this . config . format ;
71
76
}
72
77
@@ -179,9 +184,15 @@ export class QueryHistoryManager {
179
184
}
180
185
}
181
186
182
- async handleOpenQuery ( queryHistoryItem : QueryHistoryItem ) {
187
+ async handleOpenQuery ( queryHistoryItem : QueryHistoryItem ) : Promise < void > {
183
188
const textDocument = await vscode . workspace . openTextDocument ( vscode . Uri . file ( queryHistoryItem . info . query . program . queryPath ) ) ;
184
- await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
189
+ const editor = await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
190
+ const queryText = queryHistoryItem . options . queryText ;
191
+ if ( queryText !== undefined ) {
192
+ await editor . edit ( edit => edit . replace ( textDocument . validateRange (
193
+ new vscode . Range ( 0 , 0 , textDocument . lineCount , 0 ) ) , queryText )
194
+ ) ;
195
+ }
185
196
}
186
197
187
198
async handleRemoveHistoryItem ( queryHistoryItem : QueryHistoryItem ) {
@@ -203,9 +214,9 @@ export class QueryHistoryManager {
203
214
if ( response !== undefined ) {
204
215
if ( response === '' )
205
216
// Interpret empty string response as "go back to using default"
206
- queryHistoryItem . label = undefined ;
217
+ queryHistoryItem . options . label = undefined ;
207
218
else
208
- queryHistoryItem . label = response ;
219
+ queryHistoryItem . options . label = response ;
209
220
this . treeDataProvider . refresh ( ) ;
210
221
}
211
222
}
@@ -277,7 +288,7 @@ export class QueryHistoryManager {
277
288
const current = this . treeDataProvider . getCurrent ( ) ;
278
289
if ( current != undefined ) {
279
290
// We must fire the onDidChangeTreeData event to ensure the current element can be selected
280
- // using `reveal` if the tree view was not visible when the current element was added.
291
+ // using `reveal` if the tree view was not visible when the current element was added.
281
292
this . treeDataProvider . refresh ( ) ;
282
293
this . treeView . reveal ( current ) ;
283
294
}
0 commit comments