Skip to content

Commit

Permalink
refactor: rename draggingElement -> newElement (excalidraw#8294)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
ryan-di and dwelle authored Aug 6, 2024
1 parent 8d530cf commit 3cf14c7
Show file tree
Hide file tree
Showing 17 changed files with 549 additions and 679 deletions.
9 changes: 5 additions & 4 deletions packages/excalidraw/actions/actionFinalize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export const actionFinalize = register({

const multiPointElement = appState.multiElement
? appState.multiElement
: appState.editingElement?.type === "freedraw"
? appState.editingElement
: appState.newElement?.type === "freedraw"
? appState.newElement
: null;

if (multiPointElement) {
Expand Down Expand Up @@ -176,7 +176,8 @@ export const actionFinalize = register({
? appState.activeTool
: activeTool,
activeEmbeddable: null,
draggingElement: null,
newElement: null,
selectionElement: null,
multiElement: null,
editingElement: null,
startBoundElement: null,
Expand Down Expand Up @@ -204,7 +205,7 @@ export const actionFinalize = register({
keyTest: (event, appState) =>
(event.key === KEYS.ESCAPE &&
(appState.editingLinearElement !== null ||
(!appState.draggingElement && appState.multiElement === null))) ||
(!appState.newElement && appState.multiElement === null))) ||
((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) &&
appState.multiElement !== null),
PanelComponent: ({ appState, updateData, data }) => (
Expand Down
4 changes: 3 additions & 1 deletion packages/excalidraw/actions/actionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const writeData = (
!appState.multiElement &&
!appState.resizingElement &&
!appState.editingElement &&
!appState.draggingElement
!appState.newElement &&
!appState.selectedElementsAreBeingDragged &&
!appState.selectionElement
) {
const result = updater();

Expand Down
4 changes: 2 additions & 2 deletions packages/excalidraw/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getDefaultAppState = (): Omit<
currentHoveredFontFamily: null,
cursorButton: "up",
activeEmbeddable: null,
draggingElement: null,
newElement: null,
editingElement: null,
editingGroupId: null,
editingLinearElement: null,
Expand Down Expand Up @@ -160,7 +160,7 @@ const APP_STATE_STORAGE_CONF = (<
currentHoveredFontFamily: { browser: false, export: false, server: false },
cursorButton: { browser: true, export: false, server: false },
activeEmbeddable: { browser: false, export: false, server: false },
draggingElement: { browser: false, export: false, server: false },
newElement: { browser: false, export: false, server: false },
editingElement: { browser: false, export: false, server: false },
editingGroupId: { browser: true, export: false, server: false },
editingLinearElement: { browser: false, export: false, server: false },
Expand Down
Loading

0 comments on commit 3cf14c7

Please sign in to comment.