1- import getAllDocumentations from "../documentation/getAllDocumentations" ;
21import getDocumentationName from "../getDocumentationName" ;
32import { DocumentationViewProvider } from "../provider/DocumentationViewProvider" ;
43import { showInformationMessage } from "../showMessage" ;
@@ -7,15 +6,60 @@ const togglePinned = async (
76 provider : DocumentationViewProvider ,
87 documentationId : string
98) => {
10- const index = provider . _pinnedDocumentations . indexOf ( documentationId ) ;
9+ const pinnedDocumentationIndex =
10+ provider . _pinnedDocumentations . indexOf ( documentationId ) ;
11+
12+ const documentationIndex = provider . _documentations . findIndex (
13+ ( documentation ) => documentation . id === documentationId
14+ ) ;
15+
16+ const searchDocumentationIndex = provider . _searchDocumentations . findIndex (
17+ ( documentation ) => documentation . id === documentationId
18+ ) ;
19+
20+ if ( pinnedDocumentationIndex !== - 1 ) {
21+ provider . _pinnedDocumentations . splice ( pinnedDocumentationIndex , 1 ) ;
22+
23+ if ( documentationIndex !== - 1 ) {
24+ provider . _documentations [ documentationIndex ] . isPinned = false ;
25+ }
26+
27+ if ( searchDocumentationIndex !== - 1 ) {
28+ provider . _searchDocumentations [ searchDocumentationIndex ] . isPinned = false ;
29+ }
1130
12- if ( index !== - 1 ) {
13- provider . _pinnedDocumentations . splice ( index , 1 ) ;
1431 showInformationMessage (
1532 `${ getDocumentationName ( provider , documentationId ) } unpinned.`
1633 ) ;
1734 } else {
1835 provider . _pinnedDocumentations . push ( documentationId ) ;
36+
37+ if ( documentationIndex !== - 1 ) {
38+ provider . _documentations [ documentationIndex ] . isPinned = true ;
39+ }
40+
41+ if ( searchDocumentationIndex !== - 1 ) {
42+ provider . _searchDocumentations [ searchDocumentationIndex ] . isPinned = true ;
43+
44+ provider . _documentations . push (
45+ provider . _searchDocumentations [ searchDocumentationIndex ]
46+ ) ;
47+
48+ const seenIds = new Set ( ) ;
49+
50+ const uniqueDocumentations = provider . _documentations . filter (
51+ ( documentation ) => {
52+ if ( seenIds . has ( documentation . id ) ) {
53+ return false ;
54+ }
55+ seenIds . add ( documentation . id ) ;
56+ return true ;
57+ }
58+ ) ;
59+
60+ provider . _documentations = uniqueDocumentations ;
61+ }
62+
1963 showInformationMessage (
2064 `${ getDocumentationName ( provider , documentationId ) } pinned for later.`
2165 ) ;
@@ -24,27 +68,6 @@ const togglePinned = async (
2468 await provider . savePinnedDocumentations ( ) ;
2569
2670 if ( provider . _view ) {
27- const pinnedDocumentations = await getAllDocumentations ( provider , [
28- ...provider . _pinnedDocumentations ,
29- ...provider . _searchDocumentations
30- . filter ( ( documentation ) => documentation . isPinned )
31- . map ( ( documentation ) => documentation . id ) ,
32- ] ) ;
33-
34- const seenIds = new Set ( ) ;
35-
36- const uniqueDocumentations = provider . _documentations . filter (
37- ( documentation ) => {
38- if ( seenIds . has ( documentation . id ) ) {
39- return false ;
40- }
41- seenIds . add ( documentation . id ) ;
42- return true ;
43- }
44- ) ;
45-
46- provider . _documentations = uniqueDocumentations ;
47-
4871 provider . _view . webview . postMessage ( {
4972 type : "setDocumentations" ,
5073 documentations : provider . _documentations ,
0 commit comments