Skip to content

Commit 09bb5c5

Browse files
committed
2.15.1-beta-2
1 parent 434f616 commit 09bb5c5

9 files changed

Lines changed: 73 additions & 27 deletions

File tree

manifest-beta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-excalidraw-plugin",
33
"name": "Excalidraw",
4-
"version": "2.15.beta-1",
4+
"version": "2.15.1-beta-2",
55
"minAppVersion": "1.5.7",
66
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
77
"author": "Zsolt Viczian",

src/core/managers/CommandManager.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -781,20 +781,19 @@ export class CommandManager {
781781
checkCallback: (checking:boolean) => this.plugin.forceSaveActiveView(checking),
782782
})
783783

784+
//removing raw mode. Not required. I never use it. Raw mode can still be enabled
785+
//via document properties. Only showing command palette action if raw mode is enabled
784786
this.addCommand({
785787
id: "toggle-lock",
786788
name: t("TOGGLE_LOCK"),
787789
checkCallback: (checking: boolean) => {
790+
const view = this.app.workspace.getActiveViewOfType(ExcalidrawView);
788791
if (checking) {
789-
if (
790-
Boolean(this.app.workspace.getActiveViewOfType(ExcalidrawView))
791-
) {
792-
return !(this.app.workspace.getActiveViewOfType(ExcalidrawView))
793-
.compatibilityMode;
792+
if (view) {
793+
return !view.compatibilityMode && view.textMode === TextMode.raw;
794794
}
795795
return false;
796796
}
797-
const view = this.app.workspace.getActiveViewOfType(ExcalidrawView);
798797
if (view && !view.compatibilityMode) {
799798
view.changeTextMode(
800799
view.textMode === TextMode.parsed ? TextMode.raw : TextMode.parsed,
@@ -1707,15 +1706,19 @@ export class CommandManager {
17071706
const PDFLink = this.plugin.getLastActivePDFPageLink(view.file);
17081707
if(!PDFLink) return false;
17091708
if(checking) return true;
1710-
const ea = getEA(view);
1711-
insertImageToView(
1712-
ea,
1713-
view.currentPosition,
1714-
PDFLink,
1715-
undefined,
1716-
undefined,
1717-
true,
1718-
);
1709+
(async()=>{
1710+
const ea = getEA(view) as ExcalidrawAutomate;
1711+
const id = await insertImageToView(
1712+
ea,
1713+
view.currentPosition,
1714+
PDFLink,
1715+
undefined,
1716+
undefined,
1717+
true,
1718+
);
1719+
ea.selectElementsInView([id]);
1720+
ea.destroy()
1721+
})();
17191722
},
17201723
});
17211724

src/shared/ExcalidrawAutomate.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import { FrameRenderingOptions } from "src/types/utilTypes";
8989
import { CaptureUpdateAction } from "src/constants/constants";
9090
import { AutoexportConfig } from "src/types/excalidrawViewTypes";
9191
import { FloatingModal } from "./Dialogs/FloatingModal";
92+
import { patchMobileView } from "src/utils/customEmbeddableUtils";
9293

9394
extendPlugins([
9495
HarmonyPlugin,
@@ -2753,15 +2754,19 @@ export class ExcalidrawAutomate {
27532754
errorMessage("targetView not set", "addElementsToView()");
27542755
return false;
27552756
}
2756-
const elements = this.getElements();
2757-
return await this.targetView.addElements({
2757+
const elements = this.getElements();
2758+
if(elements.some(el=>el.type === "embeddable")) {
2759+
patchMobileView(this.targetView);
2760+
}
2761+
const result = await this.targetView.addElements({
27582762
newElements: elements,
27592763
repositionToCursor,
27602764
save,
27612765
images: this.imagesDict,
27622766
newElementsOnTop,
27632767
shouldRestoreElements,
27642768
});
2769+
return result;
27652770
};
27662771

27672772
/**

src/utils/customEmbeddableUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const leafMap = new Map<string, WorkspaceLeaf>();
1313

1414
//This is definitely not the right solution, feels like sticking plaster
1515
//patch disappearing content on mobile
16+
//based on obsidian app.js, obsidian is looking for activeEditor, but active editor is in a leaf that is disconnected from root
1617
export const patchMobileView = (view: ExcalidrawView) => {
1718
if(DEVICE.isDesktop) return;
1819
console.log("patching mobile view");
@@ -21,6 +22,14 @@ export const patchMobileView = (view: ExcalidrawView) => {
2122
if(!parent.hasClass("mod-visible")) {
2223
parent.addClass("mod-visible");
2324
}
25+
//create observer here
26+
const observer = new MutationObserver(() => {
27+
if(!parent.hasClass("mod-visible")) {
28+
parent.addClass("mod-visible");
29+
}
30+
});
31+
observer.observe(parent, { attributes: true, attributeFilter: ["class"] });
32+
window.setTimeout(() => observer.disconnect(), 500);
2433
}
2534
}
2635

src/utils/excalidrawViewUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function insertImageToView(
3636
file,
3737
scale,
3838
);
39-
if(shouldInsertToView) {await ea.addElementsToView(repositionToCursor, true, true);}
39+
if(shouldInsertToView) {await ea.addElementsToView(repositionToCursor, true, true, true);}
4040
return id;
4141
}
4242

src/view/ExcalidrawView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,11 +1650,11 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
16501650
t("RAW"),
16511651
() => this.changeTextMode(TextMode.parsed),
16521652
);
1653-
this.actionButtons['isParsed'] = this.addAction(
1653+
/*this.actionButtons['isParsed'] = this.addAction(
16541654
TEXT_DISPLAY_PARSED_ICON_NAME,
16551655
t("PARSED"),
16561656
() => this.changeTextMode(TextMode.raw),
1657-
);
1657+
);*/
16581658

16591659
this.actionButtons['link'] = this.addAction("link", t("OPEN_LINK"), (ev) =>
16601660
this.handleLinkClick(ev),
@@ -1846,7 +1846,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
18461846
this.textMode = textMode;
18471847
if (textMode === TextMode.parsed) {
18481848
this.actionButtons['isRaw'].hide();
1849-
this.actionButtons['isParsed'].show();
1849+
this.actionButtons['isParsed'].hide();
18501850
} else {
18511851
this.actionButtons['isRaw'].show();
18521852
this.actionButtons['isParsed'].hide();

src/view/components/CustomEmbeddable.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ function setupPdfViewEnhancements(
9292
pdfObserverDisabledRef.current = true;
9393
setPDFViewTheme(view, pdfView);
9494
requestAnimationFrame(() => { pdfObserverDisabledRef.current = false; });
95+
96+
// Observe inline height changes on the PDF root container and reset them
97+
// this could be an obsidian bug, should be revisted later 2025-08-23
98+
const containerEl = pdfView.containerEl as HTMLElement | null;
99+
let prevHeight = containerEl?.style?.height || "";
100+
let heightObserver: MutationObserver | null = null;
101+
if (containerEl) {
102+
heightObserver = new MutationObserver(() => {
103+
const h = containerEl.style.height || "";
104+
if (h !== prevHeight) {
105+
prevHeight = h;
106+
if (h) {
107+
containerEl.style.height = "";
108+
prevHeight = "";
109+
}
110+
}
111+
});
112+
heightObserver.observe(containerEl, { attributes: true, attributeFilter: ["style"] });
113+
}
95114

96115
// Transform-aware MMB drag-to-scroll (bypasses Chromium autoscroll)
97116
const scroller = pdfView.containerEl?.querySelector(".pdf-viewer-container") || null;
@@ -185,6 +204,8 @@ function setupPdfViewEnhancements(
185204
window.removeEventListener("pointermove", onPointerMove, { capture: true } as any);
186205
window.removeEventListener("pointerup", onPointerUp, { capture: true } as any);
187206
window.removeEventListener("pointercancel", onPointerUp,{ capture: true } as any);
207+
heightObserver?.disconnect();
208+
heightObserver = null;
188209
};
189210
(pdfObserverRef as any).currentCleanup = () => { cleanupPan(); };
190211

@@ -416,6 +437,8 @@ function RenderObsidianView(
416437
node: null,
417438
editNode: null,
418439
};
440+
441+
patchMobileView(view);
419442
//if subpath is defined, create a canvas node else create a workspace leaf
420443
if(subpath && view.canvasNodeFactory.isInitialized() && file.extension.toLowerCase() === "md") {
421444
setKeepOnTop();
@@ -446,7 +469,6 @@ function RenderObsidianView(
446469
containerRef.current.appendChild(rootSplit.containerEl);
447470
setColors(containerRef.current, element, mdProps, canvasColor, viewType);
448471
}
449-
patchMobileView(view);
450472
view.updateEmbeddableLeafRef(element.id, leafRef.current);
451473

452474
if(viewType === "pdf") {
@@ -630,9 +652,9 @@ function RenderObsidianView(
630652
if (!modes) {
631653
return;
632654
}
655+
patchMobileView(view);
633656
leafRef.current.leaf.view.setMode(modes['source']);
634657
isEditingRef.current = true;
635-
patchMobileView(view);
636658
} else if (leafRef.current?.node) {
637659
//Handle canvas node
638660
const newTheme = getTheme(view, themeRef.current);

src/view/components/menu/EmbeddableActionsMenu.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,30 +131,33 @@ export class EmbeddableMenu {
131131
this.updateElement(`#page=${page}`, element, pdfFile, false);
132132
}
133133

134-
private actionInsertPageAsImage (element: ExcalidrawEmbeddableElement) {
134+
private async actionInsertPageAsImage (element: ExcalidrawEmbeddableElement) {
135135
if(!element) return;
136136
const pdfView = this.view.getEmbeddableLeafElementById(element.id)?.node?.child;
137137
if(!pdfView) return;
138138
const page = getActivePDFPageNumberFromPDFView(pdfView);
139139
if(!page) return;
140140
const pdfFile: TFile = pdfView?.file;
141141
if(!pdfFile) return;
142-
const ea = getEA(this.view);
142+
const ea = getEA(this.view) as ExcalidrawAutomate;
143+
ea.selectElementsInView([]);
143144
const x = element.x + element.width + 20;
144145
const y = element.y;
145146
const path = this.view.app.metadataCache.fileToLinktext(
146147
pdfFile,
147148
this.view.file.path,
148149
false,
149150
)
150-
insertImageToView(
151+
const id = await insertImageToView(
151152
ea,
152153
{x,y},
153154
`${path}#page=${page}`,
154155
undefined,
155156
undefined,
156157
false,
157158
);
159+
ea.selectElementsInView([id]);
160+
ea.destroy();
158161
}
159162

160163
private async actionMarkdownBlock (file: TFile, subpath: string, element: ExcalidrawEmbeddableElement) {

styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,8 @@ textarea.excalidraw-wysiwyg, .excalidraw input {
875875

876876
.excalidraw__embeddable-container .pdf-toolbar-right {
877877
display: none;
878+
}
879+
880+
.excalidraw-scriptengine-install .modal-close-button {
881+
z-index: 9999;
878882
}

0 commit comments

Comments
 (0)