mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix elements insert position and viewport centering
This commit is contained in:
parent
d070760b2f
commit
9b1c88eed9
4 changed files with 21 additions and 40 deletions
|
@ -2244,11 +2244,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||
},
|
||||
);
|
||||
|
||||
private addElementsFromPasteOrLibrary = (opts: {
|
||||
addElementsFromPasteOrLibrary = (opts: {
|
||||
elements: readonly ExcalidrawElement[];
|
||||
files: BinaryFiles | null;
|
||||
position: { clientX: number; clientY: number } | "cursor" | "center";
|
||||
retainSeed?: boolean;
|
||||
fitToContent?: boolean;
|
||||
}) => {
|
||||
const elements = restoreElements(opts.elements, null, undefined);
|
||||
const [minX, minY, maxX, maxY] = getCommonBounds(elements);
|
||||
|
@ -2353,6 +2354,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||
},
|
||||
);
|
||||
this.setActiveTool({ type: "selection" });
|
||||
|
||||
if (opts.fitToContent) {
|
||||
this.scrollToContent(newElements, {
|
||||
fitToContent: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private addTextFromPaste(text: string, isPlainPaste = false) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useState, useRef, useEffect } from "react";
|
||||
import { AppState, BinaryFiles, NormalizedZoomValue } from "../types";
|
||||
import { AppState, BinaryFiles } from "../types";
|
||||
import { updateActiveTool } from "../utils";
|
||||
import { useApp, useExcalidrawSetAppState } from "./App";
|
||||
import { Button } from "./Button";
|
||||
|
@ -140,17 +140,9 @@ const MermaidToExcalidraw = ({
|
|||
mermaidToExcalidrawLib.current.graphToExcalidraw(mermaidGraphData);
|
||||
|
||||
data.current = {
|
||||
elements: convertToExcalidrawElements(
|
||||
elements,
|
||||
{
|
||||
...appState,
|
||||
zoom: { ...appState.zoom, value: 1 as NormalizedZoomValue },
|
||||
},
|
||||
{
|
||||
regenerateIds: true,
|
||||
transformViewportToSceneCoords: true,
|
||||
},
|
||||
),
|
||||
elements: convertToExcalidrawElements(elements, {
|
||||
regenerateIds: true,
|
||||
}),
|
||||
files,
|
||||
};
|
||||
const parent = canvasNode.parentElement!;
|
||||
|
@ -186,12 +178,12 @@ const MermaidToExcalidraw = ({
|
|||
|
||||
const onSelect = () => {
|
||||
const { elements: newElements, files } = data.current;
|
||||
app.scene.replaceAllElements([...elements, ...newElements]);
|
||||
app.addFiles(Object.values(files || []));
|
||||
app.scrollToContent(newElements);
|
||||
|
||||
app.setSelection(newElements);
|
||||
|
||||
app.addElementsFromPasteOrLibrary({
|
||||
elements: newElements,
|
||||
files,
|
||||
position: "center",
|
||||
fitToContent: true,
|
||||
});
|
||||
onClose();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue