Skip to content

Commit

Permalink
Close #4522 New config to control the filter text of citation suggest…
Browse files Browse the repository at this point in the history
…ions: `intellisense.citation.filterText`
  • Loading branch information
James-Yu committed Feb 6, 2025
1 parent 15bc97b commit 2843525
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,25 @@
"Show publication authors in the inline mode."
]
},
"latex-workshop.intellisense.citation.filterText": {
"scope": "resource",
"type": "array",
"items": {
"type": "string",
"enum": [
"bibtex key",
"title",
"other fields"
],
"enumDescriptions": [
"BibTeX keys.",
"Publication titles.",
"Other BibTeX fields except for title, order preserved as defined in BibTeX."
]
},
"default": ["bibtex key", "title", "other fields"],
"markdownDescription": "Defines what contents are used to filter citation entries when user types characters in inline mode. Sorting is somewhat controlled by the order of contents defined by this config."
},
"latex-workshop.intellisense.citation.format": {
"scope": "resource",
"type": "array",
Expand Down
15 changes: 14 additions & 1 deletion src/completion/completer/citation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ function provide(uri: vscode.Uri, line: string, position: vscode.Position): Comp
}
}
})
// Retrieve the list of fields to filter the completion items
const filterContents = configuration.get('latex-workshop.intellisense.citation.filterText') as ('bibtex key' | 'title' | 'other fields')[]
// Construct the filter text for each item
const getFilterText = (item: CitationItem): string => {
return filterContents
.map(filterContent => ({
'bibtex key': item.key,
'title': item.fields.title || '',
'other fields': item.fields.join(fields.filter(field => field !== 'title'), false)
}[filterContent] || ''))
.filter(text => text !== '')
.join(' ')
}
return [...items, ...alts].map(item => {
// Compile the completion item label
switch(label) {
Expand All @@ -134,7 +147,7 @@ function provide(uri: vscode.Uri, line: string, position: vscode.Position): Comp
}
break
}
item.filterText = item.key + ' ' + item.fields.title + ' ' + item.fields.join(fields.filter(field => field !== 'title'), false)
item.filterText = getFilterText(item)
item.insertText = item.key
item.range = range
// We need two spaces to ensure md newline
Expand Down

0 comments on commit 2843525

Please sign in to comment.