Skip to content

Commit c019767

Browse files
Fix #1242 - attachments are not considered in the context of orphan notes
A note that only has outbound links to attachments is now still considered an orphan.
1 parent 5e8b817 commit c019767

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/foam-vscode/src/core/services/attachment-provider.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { FoamWorkspace } from '../model/workspace';
44
import { IDisposable } from '../common/lifecycle';
55
import { ResourceProvider } from '../model/provider';
66

7-
const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
7+
export const imageExtensions = [
8+
'.png',
9+
'.jpg',
10+
'.jpeg',
11+
'.gif',
12+
'.svg',
13+
'.webp',
14+
];
815

916
const asResource = (uri: URI): Resource => {
1017
const type = imageExtensions.includes(uri.getExtension())

packages/foam-vscode/src/features/panels/orphans.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as vscode from 'vscode';
22
import { Foam } from '../../core/model/foam';
33
import { createMatcherAndDataStore } from '../../services/editor';
4-
import { getOrphansConfig } from '../../settings';
4+
import { getAttachmentsExtensions, getOrphansConfig } from '../../settings';
55
import { GroupedResourcesTreeDataProvider } from './utils/grouped-resources-tree-data-provider';
66
import { ResourceTreeItem, UriTreeItem } from './utils/tree-view-utils';
77
import { IMatcher } from '../../core/services/datastore';
88
import { FoamWorkspace } from '../../core/model/workspace';
99
import { FoamGraph } from '../../core/model/graph';
10+
import { URI } from '../../core/model/uri';
11+
import { imageExtensions } from '../../core/services/attachment-provider';
1012

1113
const EXCLUDE_TYPES = ['image', 'attachment'];
1214
export default async function activate(
@@ -66,6 +68,13 @@ export class OrphanTreeView extends GroupedResourcesTreeDataProvider {
6668
.filter(
6769
uri =>
6870
!EXCLUDE_TYPES.includes(this.workspace.find(uri)?.type) &&
69-
this.graph.getConnections(uri).length === 0
71+
this.graph.getBacklinks(uri).length === 0 &&
72+
this.graph.getLinks(uri).filter(c => !isAttachment(c.target))
73+
.length === 0
7074
);
7175
}
76+
77+
function isAttachment(uri: URI) {
78+
const ext = [...getAttachmentsExtensions(), ...imageExtensions];
79+
return ext.includes(uri.getExtension());
80+
}

0 commit comments

Comments
 (0)