From ee2e95ec01493ff644dde00a79261fe820f7ee11 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Thu, 10 Oct 2024 11:33:44 +0100 Subject: [PATCH] Merge pull request #20987 from overleaf/mj-write-and-cite-settings-icons [web] Add setting icons to Write and Cite section headers GitOrigin-RevId: 18e5eefeb1271d17812b83f152e4d464a66185f8 --- services/web/config/settings.defaults.js | 1 + .../languages/latex/completions/references.ts | 2 ++ .../languages/latex/completions/sections.ts | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 services/web/frontend/js/features/source-editor/languages/latex/completions/sections.ts 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 +}