File tree 4 files changed +76
-5
lines changed
4 files changed +76
-5
lines changed Original file line number Diff line number Diff line change 405
405
"title" : " Expand all" ,
406
406
"icon" : " $(expand-all)"
407
407
},
408
+ {
409
+ "command" : " foam-vscode.views.tags-explorer.focus" ,
410
+ "title" : " Focus on tag" ,
411
+ "icon" : " $(symbol-number)"
412
+ },
408
413
{
409
414
"command" : " foam-vscode.views.placeholders.show:for-current-file" ,
410
415
"title" : " Show placeholders in current file" ,
Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ export class NavigationProvider
157
157
} )
158
158
) ;
159
159
160
- return targets
160
+ const links : vscode . DocumentLink [ ] = targets
161
161
. filter ( o => o . target . isPlaceholder ( ) ) // links to resources are managed by the definition provider
162
162
. map ( o => {
163
163
const command = CREATE_NOTE_COMMAND . forPlaceholder (
@@ -180,5 +180,26 @@ export class NavigationProvider
180
180
documentLink . tooltip = `Create note for '${ o . target . path } '` ;
181
181
return documentLink ;
182
182
} ) ;
183
+
184
+ const tags : vscode . DocumentLink [ ] = resource . tags . map ( tag => {
185
+ const command = {
186
+ name : 'foam-vscode.views.tags-explorer.focus' ,
187
+ params : [ tag . label , documentUri ] ,
188
+ } ;
189
+
190
+ const documentLink = new vscode . DocumentLink (
191
+ new vscode . Range (
192
+ tag . range . start . line ,
193
+ tag . range . start . character ,
194
+ tag . range . end . line ,
195
+ tag . range . end . character
196
+ ) ,
197
+ commandAsURI ( command )
198
+ ) ;
199
+ documentLink . tooltip = `Explore tag '${ tag . label } '` ;
200
+ return documentLink ;
201
+ } ) ;
202
+
203
+ return links . concat ( tags ) ;
183
204
}
184
205
}
Original file line number Diff line number Diff line change @@ -54,6 +54,51 @@ export default async function activate(
54
54
provider ,
55
55
node => node . contextValue === 'tag' || node . contextValue === 'folder'
56
56
)
57
+ ) ,
58
+ vscode . commands . registerCommand (
59
+ `foam-vscode.views.${ provider . providerId } .focus` ,
60
+ async ( tag ?: string , source ?: object ) => {
61
+ if ( tag == null ) {
62
+ tag = await vscode . window . showQuickPick (
63
+ Array . from ( foam . tags . tags . keys ( ) ) ,
64
+ {
65
+ title : 'Select a tag to focus' ,
66
+ }
67
+ ) ;
68
+ }
69
+ if ( tag == null ) {
70
+ return ;
71
+ }
72
+ const tagItem = ( await provider . findTreeItemByPath (
73
+ provider . valueToPath ( tag )
74
+ ) ) as TagItem ;
75
+ if ( tagItem == null ) {
76
+ return ;
77
+ }
78
+ await treeView . reveal ( tagItem , {
79
+ select : true ,
80
+ focus : true ,
81
+ expand : true ,
82
+ } ) ;
83
+ const children = await provider . getChildren ( tagItem ) ;
84
+ const sourceUri = source ? new URI ( source ) : undefined ;
85
+ const resourceItem = sourceUri
86
+ ? children . find (
87
+ t =>
88
+ t instanceof ResourceTreeItem &&
89
+ sourceUri . isEqual ( t . resource ?. uri )
90
+ )
91
+ : undefined ;
92
+ // doing it as a two reveal process as revealing just the resource
93
+ // was only working when the tag item was already expanded
94
+ if ( resourceItem ) {
95
+ treeView . reveal ( resourceItem , {
96
+ select : true ,
97
+ focus : true ,
98
+ expand : false ,
99
+ } ) ;
100
+ }
101
+ }
57
102
)
58
103
) ;
59
104
}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import markdownItRegex from 'markdown-it-regex';
4
4
import { FoamWorkspace } from '../../core/model/workspace' ;
5
5
import { Logger } from '../../core/utils/log' ;
6
6
import { isNone } from '../../core/utils' ;
7
+ import { commandAsURI } from '../../utils/commands' ;
7
8
8
9
export const markdownItFoamTags = (
9
10
md : markdownit ,
@@ -14,10 +15,7 @@ export const markdownItFoamTags = (
14
15
regex : / (?< = ^ | \s ) ( # [ 0 - 9 ] * [ \p{ L} / _ - ] [ \p{ L} \p{ N} / _ - ] * ) / u,
15
16
replace : ( tag : string ) => {
16
17
try {
17
- const resource = workspace . find ( tag ) ;
18
- if ( isNone ( resource ) ) {
19
- return getFoamTag ( tag ) ;
20
- }
18
+ return getFoamTag ( tag ) ;
21
19
} catch ( e ) {
22
20
Logger . error (
23
21
`Error while creating link for ${ tag } in Preview panel` ,
@@ -29,6 +27,8 @@ export const markdownItFoamTags = (
29
27
} ) ;
30
28
} ;
31
29
30
+ // Commands can't be run in the preview (see https://github.com/microsoft/vscode/issues/102532)
31
+ // for we just return the tag as a span
32
32
const getFoamTag = ( content : string ) =>
33
33
`<span class='foam-tag'>${ content } </span>` ;
34
34
You can’t perform that action at this time.
0 commit comments