From 80c13272f36a2bad78fbeb7ef3f02f5efcc1b39c Mon Sep 17 00:00:00 2001 From: lucaronin Date: Sun, 19 Apr 2026 12:53:07 +0200 Subject: [PATCH] fix: keep neighborhood reverse matches path-aware --- src/utils/noteListHelpers.test.ts | 33 +++++++++++++++++++++++++++++++ src/utils/noteListHelpers.ts | 14 ++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/utils/noteListHelpers.test.ts b/src/utils/noteListHelpers.test.ts index 88b3050b..b5b627f9 100644 --- a/src/utils/noteListHelpers.test.ts +++ b/src/utils/noteListHelpers.test.ts @@ -163,4 +163,37 @@ describe('buildRelationshipGroups', () => { expect(groups.find((group) => group.label === 'Related to')?.entries).toEqual([shared]) expect(groups.find((group) => group.label === 'Referenced By')?.entries).toEqual([shared]) }) + + it('does not treat path-qualified refs for a different note as reverse matches', () => { + const parent = makeEntry({ + path: '/vault/projects/alpha.md', + filename: 'alpha.md', + title: 'Alpha', + isA: 'Project', + }) + const archiveAlpha = makeEntry({ + path: '/vault/archive/alpha.md', + filename: 'alpha.md', + title: 'Alpha Archive', + isA: 'Project', + }) + const unrelatedChild = makeEntry({ + path: '/vault/notes/child.md', + filename: 'child.md', + title: 'Child Note', + isA: 'Note', + belongsTo: ['[[archive/alpha]]'], + }) + const unrelatedEvent = makeEntry({ + path: '/vault/events/event.md', + filename: 'event.md', + title: 'Review', + isA: 'Event', + relatedTo: ['[[archive/alpha]]'], + }) + + const groups = buildRelationshipGroups(parent, [parent, archiveAlpha, unrelatedChild, unrelatedEvent]) + + expect(groups).toEqual([]) + }) }) diff --git a/src/utils/noteListHelpers.ts b/src/utils/noteListHelpers.ts index a71a5d17..be95de6a 100644 --- a/src/utils/noteListHelpers.ts +++ b/src/utils/noteListHelpers.ts @@ -67,8 +67,20 @@ export function formatSearchSubtitle(entry: VaultEntry): string { return parts.join(' \u00b7 ') } +function refMatchesEntry(ref: string, entry: VaultEntry): boolean { + const target = wikilinkTarget(ref).trim() + if (!target) return false + + if (target.includes('/')) { + const normalizedTarget = target.replace(/^\/+/, '').replace(/\.md$/, '').toLowerCase() + return entry.path.toLowerCase().endsWith(`/${normalizedTarget}.md`) + } + + return resolveEntry([entry], target) !== undefined +} + function refsMatch(refs: string[], entry: VaultEntry): boolean { - return refs.some((ref) => resolveEntry([entry], wikilinkTarget(ref)) !== undefined) + return refs.some((ref) => refMatchesEntry(ref, entry)) } function resolveRefs(refs: string[], entries: VaultEntry[]): VaultEntry[] {