@@ -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