Skip to content

Commit

Permalink
Fix duplicate check not working across note types (#830)
Browse files Browse the repository at this point in the history
* Fix duplicate check not working across note types

* Add invalidNoteId

---------

Co-authored-by: James Maa <jmaa@berkeley.edu>
  • Loading branch information
Kuuuube and jamesmaa authored Apr 16, 2024
1 parent 6e1cb32 commit 669d277
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {logErrorLevelToNumber} from '../core/log-utilities.js';
import {log} from '../core/log.js';
import {isObjectNotArray} from '../core/object-utilities.js';
import {clone, deferPromise, promiseTimeout} from '../core/utilities.js';
import {isNoteDataValid} from '../data/anki-util.js';
import {invalidNoteId, isNoteDataValid} from '../data/anki-util.js';
import {arrayBufferToBase64} from '../data/array-buffer-util.js';
import {OptionsUtil} from '../data/options-util.js';
import {getAllPermissions, hasPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js';
Expand Down Expand Up @@ -595,6 +595,10 @@ export class Backend {

const valid = isNoteDataValid(note);

if (isDuplicate && duplicateNoteIds[originalIndices.indexOf(i)].length === 0) {
duplicateNoteIds[originalIndices.indexOf(i)] = [invalidNoteId];
}

const noteIds = isDuplicate ? duplicateNoteIds[originalIndices.indexOf(i)] : null;
const noteInfos = (fetchAdditionalInfo && noteIds !== null && noteIds.length > 0) ? await this._anki.notesInfo(noteIds) : [];

Expand Down
2 changes: 2 additions & 0 deletions ext/js/data/anki-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ export function isNoteDataValid(note) {
Object.entries(fields).length > 0
);
}

export const invalidNoteId = -1;
8 changes: 6 additions & 2 deletions ext/js/display/display-anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {log} from '../core/log.js';
import {toError} from '../core/to-error.js';
import {deferPromise} from '../core/utilities.js';
import {AnkiNoteBuilder} from '../data/anki-note-builder.js';
import {isNoteDataValid} from '../data/anki-util.js';
import {invalidNoteId, isNoteDataValid} from '../data/anki-util.js';
import {PopupMenu} from '../dom/popup-menu.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {TemplateRendererProxy} from '../templates/template-renderer-proxy.js';
Expand Down Expand Up @@ -425,7 +425,11 @@ export class DisplayAnki {

if (Array.isArray(noteIds) && noteIds.length > 0) {
if (allNoteIds === null) { allNoteIds = new Set(); }
for (const noteId of noteIds) { allNoteIds.add(noteId); }
for (const noteId of noteIds) {
if (noteId !== invalidNoteId) {
allNoteIds.add(noteId);
}
}
}

if (displayTags !== 'never' && Array.isArray(noteInfos)) {
Expand Down

0 comments on commit 669d277

Please sign in to comment.