diff --git a/services/web/config/settings.defaults.js b/services/web/config/settings.defaults.js index ef209f4f34..a9b9fa119c 100644 --- a/services/web/config/settings.defaults.js +++ b/services/web/config/settings.defaults.js @@ -964,6 +964,7 @@ module.exports = { offlineModeToolbarButtons: [], settingsEntries: [], autoCompleteExtensions: [], + sectionTitleGenerators: [], }, moduleImportSequence: [ diff --git a/services/web/frontend/js/features/source-editor/languages/latex/completions/references.ts b/services/web/frontend/js/features/source-editor/languages/latex/completions/references.ts index 42db5829d0..6a05e858d1 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/completions/references.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/completions/references.ts @@ -5,6 +5,7 @@ import { CompletionContext } from '@codemirror/autocomplete' import { Completions } from './types' import { metadataState } from '../../../extensions/language' import { extendRequiredParameter } from './apply' +import { maybeGetSectionForOption } from './sections' export function buildReferenceCompletions( completions: Completions, @@ -21,6 +22,7 @@ export function buildReferenceCompletions( type: 'reference', label: referenceKey, extend: extendRequiredParameter, + section: maybeGetSectionForOption(context, 'references'), deduplicate: { key: referenceKey, priority: 1, diff --git a/services/web/frontend/js/features/source-editor/languages/latex/completions/sections.ts b/services/web/frontend/js/features/source-editor/languages/latex/completions/sections.ts new file mode 100644 index 0000000000..75cf95eee4 --- /dev/null +++ b/services/web/frontend/js/features/source-editor/languages/latex/completions/sections.ts @@ -0,0 +1,25 @@ +import { CompletionContext, CompletionSection } from '@codemirror/autocomplete' +import importOverleafModules from '../../../../../../macros/import-overleaf-module.macro' + +type SectionGenerator = ( + context: CompletionContext, + type: string +) => CompletionSection | string | undefined +const sectionTitleGenerators: Array = importOverleafModules( + 'sectionTitleGenerators' +).map( + (item: { import: { getSection: SectionGenerator } }) => item.import.getSection +) + +export function maybeGetSectionForOption( + context: CompletionContext, + type: string +) { + for (const generator of sectionTitleGenerators) { + const section = generator(context, type) + if (section !== undefined) { + return section + } + } + return undefined +}