mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
support for the hover editor
This commit is contained in:
@@ -67,12 +67,11 @@ import {
|
||||
getSVGPadding,
|
||||
getWithBackground,
|
||||
hasExportTheme,
|
||||
rotatedDimensions,
|
||||
scaleLoadedImage,
|
||||
svgToBase64,
|
||||
viewportCoordsToSceneCoords,
|
||||
} from "./utils/Utils";
|
||||
import { getNewOrAdjacentLeaf } from "./utils/ObsidianUtils";
|
||||
import { getNewOrAdjacentLeaf, getParentOfClass } from "./utils/ObsidianUtils";
|
||||
import { splitFolderAndFilename } from "./utils/FileUtils";
|
||||
import { NewFileActions, Prompt } from "./dialogs/Prompt";
|
||||
import { ClipboardData } from "@zsviczian/excalidraw/types/clipboard";
|
||||
@@ -874,18 +873,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
private offsetLeft: number = 0;
|
||||
private offsetTop: number = 0;
|
||||
private addParentMoveObserver() {
|
||||
const getParentOfClass = (element: HTMLElement, cssClass: string) => {
|
||||
let parent = element.parentElement;
|
||||
while (
|
||||
parent &&
|
||||
!(parent instanceof window.HTMLBodyElement) &&
|
||||
!parent.classList.contains(cssClass)
|
||||
) {
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
return parent.classList.contains(cssClass) ? parent : null;
|
||||
};
|
||||
|
||||
|
||||
const parent =
|
||||
getParentOfClass(this.containerEl, "popover") ??
|
||||
getParentOfClass(this.containerEl, "workspace-leaf");
|
||||
@@ -893,6 +881,8 @@ export default class ExcalidrawView extends TextFileView {
|
||||
return;
|
||||
}
|
||||
|
||||
const inHoverEditorLeaf = parent.classList.contains("popover");
|
||||
|
||||
this.offsetLeft = parent.offsetLeft;
|
||||
this.offsetTop = parent.offsetTop;
|
||||
const self = this;
|
||||
@@ -915,7 +905,7 @@ export default class ExcalidrawView extends TextFileView {
|
||||
|
||||
this.parentMoveObserver.observe(parent, {
|
||||
attributeOldValue: true,
|
||||
attributeFilter: parent.classList.contains("popover")
|
||||
attributeFilter: inHoverEditorLeaf
|
||||
? ["data-x", "data-y"]
|
||||
: ["class", "style"],
|
||||
});
|
||||
|
||||
@@ -5,11 +5,39 @@ import {
|
||||
import ExcalidrawPlugin from "../main";
|
||||
import { checkAndCreateFolder, splitFolderAndFilename } from "./FileUtils";
|
||||
|
||||
export const getParentOfClass = (element: HTMLElement, cssClass: string):HTMLElement | null => {
|
||||
let parent = element.parentElement;
|
||||
while (
|
||||
parent &&
|
||||
!(parent instanceof window.HTMLBodyElement) &&
|
||||
!parent.classList.contains(cssClass)
|
||||
) {
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
return parent.classList.contains(cssClass) ? parent : null;
|
||||
};
|
||||
|
||||
export const getNewOrAdjacentLeaf = (
|
||||
plugin: ExcalidrawPlugin,
|
||||
leaf: WorkspaceLeaf
|
||||
): WorkspaceLeaf => {
|
||||
const inHoverEditorLeaf = leaf.view?.containerEl
|
||||
? getParentOfClass(leaf.view.containerEl, "popover") !== null
|
||||
: false;
|
||||
|
||||
if (inHoverEditorLeaf) {
|
||||
const mainLeaves = app.workspace.getLayout().main.children.filter((c:any) => c.type === "leaf");
|
||||
if(mainLeaves.length === 0) {
|
||||
//@ts-ignore
|
||||
return leafToUse = app.workspace.createLeafInParent(app.workspace.rootSplit);
|
||||
}
|
||||
const targetLeaf = app.workspace.getLeafById(mainLeaves[0].id);
|
||||
if (plugin.settings.openInAdjacentPane) {
|
||||
return targetLeaf;
|
||||
}
|
||||
return plugin.app.workspace.createLeafBySplit(targetLeaf);
|
||||
}
|
||||
|
||||
if (plugin.settings.openInAdjacentPane) {
|
||||
let leafToUse = plugin.app.workspace.getAdjacentLeafInDirection(
|
||||
leaf,
|
||||
|
||||
Reference in New Issue
Block a user