feat: streamline Kiku duplicate grouping and popup flow (#38)

This commit is contained in:
2026-04-01 00:04:03 -07:00
committed by GitHub
parent 3502cdc607
commit d6c72806bb
31 changed files with 1227 additions and 36 deletions

View File

@@ -41,6 +41,7 @@ interface FieldGroupingDeps {
excludeNoteId: number,
noteInfo: FieldGroupingNoteInfo,
) => Promise<number | null>;
getTrackedDuplicateNoteIds?: (noteId: number) => number[] | null;
hasAllConfiguredFields: (
noteInfo: FieldGroupingNoteInfo,
configuredFieldNames: (string | undefined)[],
@@ -117,11 +118,11 @@ export class FieldGroupingService {
return;
}
const duplicateNoteId = await this.deps.findDuplicateNote(
expressionText,
noteId,
noteInfoBeforeUpdate,
);
const trackedDuplicateNoteIds = this.deps.getTrackedDuplicateNoteIds?.(noteId) ?? null;
const duplicateNoteId =
trackedDuplicateNoteIds !== null
? pickMostRecentDuplicateNoteId(trackedDuplicateNoteIds, noteId)
: await this.deps.findDuplicateNote(expressionText, noteId, noteInfoBeforeUpdate);
if (duplicateNoteId === null) {
this.deps.showOsdNotification('No duplicate card found');
return;
@@ -243,3 +244,17 @@ export class FieldGroupingService {
}
}
}
function pickMostRecentDuplicateNoteId(
duplicateNoteIds: number[],
excludeNoteId: number,
): number | null {
let bestNoteId: number | null = null;
for (const noteId of duplicateNoteIds) {
if (noteId === excludeNoteId) continue;
if (bestNoteId === null || noteId > bestNoteId) {
bestNoteId = noteId;
}
}
return bestNoteId;
}