Skip to content

Commit 5ffd4f7

Browse files
committed
refactor: move update-active-view-of-document to view.on-unload
1 parent 28b403c commit 5ffd4f7

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { LINEAGE_VIEW_TYPE, LineageView } from 'src/view/view';
2+
3+
export const refreshActiveViewOfDocument = (view: LineageView) => {
4+
const views: [string, string][] = view.plugin.app.workspace
5+
.getLeavesOfType(LINEAGE_VIEW_TYPE)
6+
.map((leaf) =>
7+
leaf.view instanceof LineageView &&
8+
leaf.view !== view &&
9+
leaf.view.file
10+
? [leaf.view.id, leaf.view.file.path]
11+
: null,
12+
)
13+
.filter((x) => x) as [string, string][];
14+
15+
view.plugin.store.dispatch({
16+
type: 'plugin/documents/refresh-active-view-of-document',
17+
payload: { views },
18+
});
19+
};

src/stores/plugin/subscriptions/on-workspace-event.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Lineage from 'src/main';
2-
import { LINEAGE_VIEW_TYPE, LineageView } from 'src/view/view';
2+
import { LineageView } from 'src/view/view';
33
import { removeStaleDocuments } from 'src/stores/plugin/subscriptions/effects/remove-stale-documents/remove-stale-documents';
4-
import { MarkdownView } from 'obsidian';
54

65
export const onWorkspaceEvent = (plugin: Lineage) => {
76
const onActiveLeafChangeRef = plugin.app.workspace.on(
@@ -16,19 +15,6 @@ export const onWorkspaceEvent = (plugin: Lineage) => {
1615
viewId: view.id,
1716
},
1817
});
19-
} else if (view instanceof MarkdownView) {
20-
const views: [string, string][] = plugin.app.workspace
21-
.getLeavesOfType(LINEAGE_VIEW_TYPE)
22-
.map((leaf) =>
23-
leaf.view instanceof LineageView && leaf.view.file
24-
? [leaf.view.id, leaf.view.file.path]
25-
: null,
26-
)
27-
.filter((x) => x) as [string, string][];
28-
plugin.store.dispatch({
29-
type: 'plugin/documents/refresh-active-view-of-document',
30-
payload: { views },
31-
});
3218
}
3319
plugin.store.dispatch({
3420
type: 'plugin/echo/workspace/active-leaf-change',

src/view/view.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { lang } from 'src/lang/lang';
4949
import { DebouncedMinimapEffects } from 'src/stores/minimap/subscriptions/effects/debounced-minimap-effects';
5050
import { updateFrontmatter } from 'src/stores/view/subscriptions/actions/document/update-frontmatter';
5151
import { loadFullDocument } from 'src/stores/view/subscriptions/actions/document/load-full-document';
52+
import { refreshActiveViewOfDocument } from 'src/stores/plugin/actions/refresh-active-view-of-document';
5253

5354
export const LINEAGE_VIEW_TYPE = 'lineage';
5455

@@ -138,6 +139,7 @@ export class LineageView extends TextFileView {
138139
for (const s of this.onDestroyCallbacks) {
139140
s();
140141
}
142+
refreshActiveViewOfDocument(this);
141143
}
142144

143145
clear(): void {

0 commit comments

Comments
 (0)