calculate coords based on container viewport position (#1955)

* feat: calculate coords based on parent left and top so it renders correctly in host App

* fix text

* move offsets to state & fix bugs

* fix text jumping

* account for zoom in textWysiwyg & undo incorrect offsetting

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Aakansha Doshi 2020-07-27 17:18:49 +05:30 committed by GitHub
parent 63edbb9517
commit 7eff6893c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 361 additions and 179 deletions

View file

@ -6,7 +6,6 @@ import {
import { AppState } from "../types";
import { DataState } from "./types";
import { isInvisiblySmallElement, getNormalizedDimensions } from "../element";
import { calculateScrollCenter } from "../scene";
import { randomId } from "../random";
import {
FONT_FAMILY,
@ -110,8 +109,7 @@ const migrateElement = (
export const restore = (
savedElements: readonly ExcalidrawElement[],
savedState: AppState | null,
opts?: { scrollToContent: boolean },
savedState: MarkOptional<AppState, "offsetTop" | "offsetLeft"> | null,
): DataState => {
const elements = savedElements.reduce((elements, element) => {
// filtering out selection, which is legacy, no longer kept in elements,
@ -125,13 +123,6 @@ export const restore = (
return elements;
}, [] as ExcalidrawElement[]);
if (opts?.scrollToContent && savedState) {
savedState = {
...savedState,
...calculateScrollCenter(elements, savedState, null),
};
}
return {
elements: elements,
appState: savedState,