From 6b7a77b4b201595e309bc3f5c60358ea6aedaefc Mon Sep 17 00:00:00 2001 From: Maria Florencia Besteiro Gonzalez Date: Fri, 7 Aug 2026 14:29:18 +0200 Subject: [PATCH] Merge pull request #36239 from overleaf/mfb-show-duplicate-in-visual-bib-editor Show duplicate entries in visual bib editor GitOrigin-RevId: 32e4e41a751624a2142c7fd2c5e5de5a5d3905f5 --- .../js/features/bibtex/bibtex-entry.mts | 20 ++++++++++++++++--- services/web/locales/en.json | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/bibtex/bibtex-entry.mts b/services/web/frontend/js/features/bibtex/bibtex-entry.mts index 00b3bc18bc..2f6e456c7c 100644 --- a/services/web/frontend/js/features/bibtex/bibtex-entry.mts +++ b/services/web/frontend/js/features/bibtex/bibtex-entry.mts @@ -9,6 +9,7 @@ type BibtexEntryOptions = { key?: string fields?: Fields id?: string + occurrenceIndex?: number updatedAt?: Date } @@ -41,11 +42,22 @@ export class BibtexEntry { private readonly _id: string /** - * Stable identifier. Defaults to the citation key for in-project entries; - * set to the database record ID for library entries. + * Position of this entry among entries that share its citation key, in + * document order (0-based). In-project entries can share a citation key, so + * this disambiguates them. It is positional metadata (not content), assigned + * by `useBibtexEntries` once the full, ordered entry list is known. + */ + occurrenceIndex: number + + /** + * Stable identifier. + * - Library entries: the database record ID. + * - In-project entries: `${key}#${occurrenceIndex}`, so duplicate keys still + * get distinct ids and can be located unambiguously in the document. */ get id(): string { - return this._id || this.key + if (this._id) return this._id + return `${this.key}#${this.occurrenceIndex}` } constructor({ @@ -53,12 +65,14 @@ export class BibtexEntry { key = '', fields = new Map(), id = '', + occurrenceIndex = 0, updatedAt, }: BibtexEntryOptions = {}) { this.type = type this.key = key this.fields = fields this._id = id + this.occurrenceIndex = occurrenceIndex this.updatedAt = updatedAt } diff --git a/services/web/locales/en.json b/services/web/locales/en.json index 0f51c0d9dc..22ff548fc5 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -289,7 +289,7 @@ "biblatex": "BibLaTeX", "bibliographies": "Bibliographies", "bibtex": "BibTeX", - "bibtex_duplicates_keys": "The file __fileName__ contains more than one entry with the citation key __key__. Only the first occurrence is shown in this list.", + "bibtex_duplicates_keys": "This citation key is used by another entry. Duplicate keys cause citation errors — rename this key or delete one of the entries.", "billed_annually_at": "Billed annually at <0>__price__ <1>(includes plan and any add-ons)", "billed_monthly_at": "Billed monthly at <0>__price__ <1>(includes plan and any add-ons)", "billed_yearly": "billed yearly",