Compare commits

..

2 Commits

Author SHA1 Message Date
zsviczian
afe01bf660 Update Scribble Helper.md 2022-04-14 09:12:01 +02:00
Zsolt Viczian
646b63e3dd support for the hover editor 2022-04-11 22:52:20 +02:00
3 changed files with 34 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
/*
![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-scribble-helper.jpg)
iOS scribble helper for better handwriting experience with text elements. If no elements are selected then the creates a text element at pointer position and you can use the edit box to modify the text with scribble. If a text element is selected then opens the input prompt where you can modify this text with scribble.
iOS scribble helper for better handwriting experience with text elements. If no elements are selected then the script creates a text element at the pointer position and you can use the edit box to modify the text with scribble. If a text element is selected then the script opens the input prompt where you can modify this text with scribble.
```javascript
*/

View File

@@ -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"],
});

View File

@@ -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,