refactor: rename draggingElement -> newElement (#8294)

* add newElement to appState

* freedraw should not be an editing element

* do not set editing element for freedraw and generic

* remove ununsed `appState.draggingElement`

* remove setting dragged for new linear element

* decouple selection element from new element

* fix hint for text bindables

* update snapshot

* fixes

* fix frame regressions

* add comments to types

* document `editingElement`

---------

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Ryan Di 2024-08-06 19:26:06 +08:00 committed by GitHub
parent 8d530cf102
commit 3cf14c73a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 554 additions and 684 deletions

View file

@ -160,7 +160,7 @@ export const getDragOffsetXY = (
};
export const dragNewElement = (
draggingElement: NonDeletedExcalidrawElement,
newElement: NonDeletedExcalidrawElement,
elementType: AppState["activeTool"]["type"],
originX: number,
originY: number,
@ -179,7 +179,7 @@ export const dragNewElement = (
y: number;
} | null = null,
) => {
if (shouldMaintainAspectRatio && draggingElement.type !== "selection") {
if (shouldMaintainAspectRatio && newElement.type !== "selection") {
if (widthAspectRatio) {
height = width / widthAspectRatio;
} else {
@ -218,17 +218,14 @@ export const dragNewElement = (
let textAutoResize = null;
// NOTE this should apply only to creating text elements, not existing
// (once we rewrite appState.draggingElement to actually mean dragging
// elements)
if (isTextElement(draggingElement)) {
height = draggingElement.height;
if (isTextElement(newElement)) {
height = newElement.height;
const minWidth = getMinTextElementWidth(
getFontString({
fontSize: draggingElement.fontSize,
fontFamily: draggingElement.fontFamily,
fontSize: newElement.fontSize,
fontFamily: newElement.fontFamily,
}),
draggingElement.lineHeight,
newElement.lineHeight,
);
width = Math.max(width, minWidth);
@ -245,7 +242,7 @@ export const dragNewElement = (
}
if (width !== 0 && height !== 0) {
mutateElement(draggingElement, {
mutateElement(newElement, {
x: newX + (originOffset?.x ?? 0),
y: newY + (originOffset?.y ?? 0),
width,