Skip to content

Commit f676be8

Browse files
committed
Keep starred status
Signed-off-by: worksofliam <mrliamallan@live.co.uk>
1 parent 23d96df commit f676be8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/views/queryHistoryView/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,26 @@ export class queryHistory implements TreeDataProvider<any> {
2727
commands.registerCommand(`vscode-db2i.queryHistory.prepend`, async (newQuery?: string) => {
2828
if (newQuery && Config.ready) {
2929
let currentList = Config.getPastQueries();
30-
const existingQuery = currentList.findIndex(queryItem => queryItem.query.trim() === newQuery.trim());
30+
const existingQueryi = currentList.findIndex(queryItem => queryItem.query.trim() === newQuery.trim());
31+
const existingQuery = currentList[existingQueryi];
32+
33+
const newQueryItem: QueryHistoryItem = {
34+
query: newQuery,
35+
unix: Math.floor(Date.now() / 1000),
36+
};
37+
38+
if (existingQuery) {
39+
newQueryItem.starred = existingQuery.starred; // Preserve starred status
40+
}
3141

3242
// If it exists, remove it
33-
if (existingQuery > 0) {
34-
currentList.splice(existingQuery, 1);
43+
if (existingQueryi > 0) {
44+
currentList.splice(existingQueryi, 1);
3545
}
3646

3747
// If it's at the top, don't add it, it's already at the top
38-
if (existingQuery !== 0) {
39-
currentList.splice(0, 0, {
40-
query: newQuery,
41-
unix: Math.floor(Date.now() / 1000)
42-
});
48+
if (existingQueryi !== 0) {
49+
currentList.splice(0, 0, newQueryItem);
4350
}
4451

4552
await Config.setPastQueries(currentList);

0 commit comments

Comments
 (0)