Skip to content

Commit e910c2f

Browse files
committed
Implement checkpoint starring functionality to prioritize and sort entries in the quick pick list
1 parent 44d6c6a commit e910c2f

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎packages/vscode/src/commands/checkpoints-command/checkpoints-command.ts‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ export const checkpoints_command = (
100100
}
101101

102102
const visible_checkpoints = checkpoints.filter((c) => !c.is_temporary)
103+
104+
visible_checkpoints.sort((a, b) => {
105+
if (a.starred && !b.starred) return -1
106+
if (!a.starred && b.starred) return 1
107+
return b.timestamp - a.timestamp
108+
})
109+
103110
quick_pick.items = [
104111
{
105112
id: 'add-new',
@@ -118,13 +125,19 @@ export const checkpoints_command = (
118125
...visible_checkpoints.map((c, index) => {
119126
return {
120127
id: c.timestamp.toString(),
121-
label: c.title,
128+
label: c.starred ? `$(star-full) ${c.title}` : c.title,
122129
description: dayjs(c.timestamp).fromNow(),
123130
detail: c.description,
124131
checkpoint: c,
125132
index,
126-
buttons:
127-
c.title == 'Created by user'
133+
buttons: [
134+
{
135+
iconPath: new vscode.ThemeIcon(
136+
c.starred ? 'star-full' : 'star-empty'
137+
),
138+
tooltip: c.starred ? 'Unstar' : 'Star'
139+
},
140+
...(c.title == 'Created by user'
128141
? [
129142
{
130143
iconPath: new vscode.ThemeIcon('edit'),
@@ -135,7 +148,8 @@ export const checkpoints_command = (
135148
tooltip: 'Delete'
136149
}
137150
]
138-
: undefined
151+
: [])
152+
]
139153
}
140154
})
141155
]
@@ -208,6 +222,29 @@ export const checkpoints_command = (
208222
}
209223
if (!item.checkpoint) return
210224

225+
if (e.button.tooltip == 'Star' || e.button.tooltip == 'Unstar') {
226+
const checkpoint_to_update = checkpoints.find(
227+
(c) => c.timestamp == item.checkpoint?.timestamp
228+
)
229+
if (checkpoint_to_update) {
230+
checkpoint_to_update.starred = !checkpoint_to_update.starred
231+
await context.workspaceState.update(
232+
CHECKPOINTS_STATE_KEY,
233+
checkpoints
234+
)
235+
}
236+
await refresh_items()
237+
const active_item = quick_pick.items.find(
238+
(i) =>
239+
(i as any).checkpoint?.timestamp === item.checkpoint?.timestamp
240+
)
241+
if (active_item) {
242+
quick_pick.activeItems = [active_item]
243+
}
244+
quick_pick.show()
245+
return
246+
}
247+
211248
if (e.button.tooltip == 'Edit Description') {
212249
is_showing_dialog = true
213250
const new_description = await vscode.window.showInputBox({

‎packages/vscode/src/commands/checkpoints-command/types/checkpoint.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface Checkpoint {
33
title: string
44
description?: string
55
is_temporary?: boolean
6+
starred?: boolean
67
}

0 commit comments

Comments
 (0)