Skip to content

Commit 2bfda66

Browse files
committed
feat: add last selected snippet to top of list
1 parent 20c0679 commit 2bfda66

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/extension.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,39 @@ export function activate (context: vscode.ExtensionContext) {
1111
'http://localhost:3033/snippets/embed-folder'
1212
)
1313

14+
const lastSelectedId = context.globalState.get('masscode:last-selected')
15+
1416
const options = data
1517
.filter(i => !i.isDeleted)
1618
.reduce((acc: vscode.QuickPickItem[], snippet) => {
1719
const fragments = snippet.content.map(fragment => {
20+
const isLastSelected = lastSelectedId === snippet.id
21+
1822
return {
19-
label: snippet.name || '',
23+
label: snippet.name || 'Untitled snippet',
2024
detail: snippet.content.length > 1 ? fragment.label : '',
2125
description: `${fragment.language}${
2226
snippet.folder?.name || 'Inbox'
23-
}`
27+
}`,
28+
picked: isLastSelected // use picked props to determine as last selected
29+
2430
}
25-
})
31+
}) as vscode.QuickPickItem[]
2632

2733
acc.push(...fragments)
2834

2935
return acc
3036
}, []) as vscode.QuickPickItem[]
3137

38+
options.sort(i => i.picked ? -1 : 1)
39+
40+
let snippet: Snippet | undefined
3241
let fragmentContent = ''
3342

3443
const picked = await vscode.window.showQuickPick(options, {
3544
placeHolder: 'Type to search...',
3645
onDidSelectItem (item: vscode.QuickPickItem) {
37-
const snippet = data.find(i => i.name === item.label)
46+
snippet = data.find(i => i.name === item.label)
3847

3948
if (snippet) {
4049
if (snippet.content.length === 1) {
@@ -54,6 +63,7 @@ export function activate (context: vscode.ExtensionContext) {
5463
if (fragmentContent.length) {
5564
vscode.env.clipboard.writeText(fragmentContent)
5665
vscode.commands.executeCommand('editor.action.clipboardPasteAction')
66+
context.globalState.update('masscode:last-selected', snippet?.id)
5767
}
5868
} catch (err) {
5969
vscode.window.showErrorMessage('massCode app is not running.')

0 commit comments

Comments
 (0)