Skip to content

Commit

Permalink
Merge pull request #2215 from zsviczian/local-graph-embed-sync
Browse files Browse the repository at this point in the history
Set local graph when embeddable is activated/deactivated #2200
  • Loading branch information
zsviczian authored Jan 15, 2025
2 parents 7cccf1d + 7eb23ab commit ed2e700
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/utils/customEmbeddableUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NonDeletedExcalidrawElement } from "@zsviczian/excalidraw/types/excalidraw/element/types";
import { DEVICE, REG_LINKINDEX_INVALIDCHARS } from "src/constants/constants";
import { getParentOfClass } from "./obsidianUtils";
import { TFile, WorkspaceLeaf } from "obsidian";
import { App, TFile, WorkspaceLeaf } from "obsidian";
import { getLinkParts } from "./utils";
import ExcalidrawView from "src/view/ExcalidrawView";

Expand Down Expand Up @@ -55,4 +55,15 @@ export const generateEmbeddableLink = (src: string, theme: "light" | "dark"):str
}
}*/
return src;
}

export function setFileToLocalGraph(app: App, file: TFile) {
let lgv;
app.workspace.iterateAllLeaves((l) => {
if (l.view?.getViewType() === "localgraph") lgv = l.view;
});
if (lgv) {
//@ts-ignore
lgv.loadFile(file);
}
}
15 changes: 14 additions & 1 deletion src/view/components/CustomEmbeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConstructableWorkspaceSplit, getContainerForDocument, isObsidianThemeDa
import { DEVICE, EXTENDED_EVENT_TYPES, KEYBOARD_EVENT_TYPES } from "src/constants/constants";
import { ExcalidrawImperativeAPI, UIAppState } from "@zsviczian/excalidraw/types/excalidraw/types";
import { ObsidianCanvasNode } from "src/view/managers/CanvasNodeFactory";
import { processLinkText, patchMobileView } from "src/utils/customEmbeddableUtils";
import { processLinkText, patchMobileView, setFileToLocalGraph } from "src/utils/customEmbeddableUtils";
import { EmbeddableMDCustomProps } from "src/shared/Dialogs/EmbeddableSettings";

declare module "obsidian" {
Expand Down Expand Up @@ -154,6 +154,15 @@ function RenderObsidianView(
}; //cleanup on unmount
}, [isActiveRef.current, containerRef.current]);

//set local graph to view when deactivating embeddables
React.useEffect(() => {
if(file === view.file) {
return;
}
if(!isActiveRef.current) {
setFileToLocalGraph(view.app, view.file);
}
}, [isActiveRef.current]);

//--------------------------------------------------------------------------------
//Mount the workspace leaf or the canvas node depending on subpath
Expand Down Expand Up @@ -408,6 +417,10 @@ function RenderObsidianView(
return;
}

if(file !== view.file) {
setFileToLocalGraph(view.app, file);
}

if(leafRef.current.leaf?.view?.getViewType() === "markdown") {
//Handle markdown leaf
//@ts-ignore
Expand Down

0 comments on commit ed2e700

Please sign in to comment.