mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-11 05:45:14 -04:00
Fix point at finalize
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
parent
a5c6befdb8
commit
b2f9f3d598
@ -32,6 +32,7 @@ import type {
|
|||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
NonDeleted,
|
NonDeleted,
|
||||||
|
PointsPositionUpdates,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
@ -55,14 +56,10 @@ export const actionFinalize = register<FormData>({
|
|||||||
perform: (elements, appState, data, app) => {
|
perform: (elements, appState, data, app) => {
|
||||||
let newElements = elements;
|
let newElements = elements;
|
||||||
const { interactiveCanvas, focusContainer, scene } = app;
|
const { interactiveCanvas, focusContainer, scene } = app;
|
||||||
const { event, sceneCoords } =
|
|
||||||
(data as {
|
|
||||||
event?: PointerEvent;
|
|
||||||
sceneCoords?: { x: number; y: number };
|
|
||||||
}) ?? {};
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
if (event && appState.selectedLinearElement) {
|
if (data && appState.selectedLinearElement) {
|
||||||
|
const { event, sceneCoords } = data;
|
||||||
const element = LinearElementEditor.getElement<ExcalidrawArrowElement>(
|
const element = LinearElementEditor.getElement<ExcalidrawArrowElement>(
|
||||||
appState.selectedLinearElement.elementId,
|
appState.selectedLinearElement.elementId,
|
||||||
elementsMap,
|
elementsMap,
|
||||||
@ -73,6 +70,11 @@ export const actionFinalize = register<FormData>({
|
|||||||
"Arrow element should exist if selectedLinearElement is set",
|
"Arrow element should exist if selectedLinearElement is set",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
sceneCoords,
|
||||||
|
"sceneCoords should be defined if actionFinalize is called with event",
|
||||||
|
);
|
||||||
|
|
||||||
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
||||||
event,
|
event,
|
||||||
appState.selectedLinearElement,
|
appState.selectedLinearElement,
|
||||||
@ -85,23 +87,15 @@ export const actionFinalize = register<FormData>({
|
|||||||
const selectedPointsIndices = newArrow
|
const selectedPointsIndices = newArrow
|
||||||
? [element.points.length - 1] // New arrow creation
|
? [element.points.length - 1] // New arrow creation
|
||||||
: appState.selectedLinearElement.selectedPointsIndices;
|
: appState.selectedLinearElement.selectedPointsIndices;
|
||||||
const draggedPoints =
|
|
||||||
|
const draggedPoints: PointsPositionUpdates =
|
||||||
selectedPointsIndices.reduce((map, index) => {
|
selectedPointsIndices.reduce((map, index) => {
|
||||||
map.set(index, {
|
map.set(index, {
|
||||||
point: newArrow
|
point: LinearElementEditor.pointFromAbsoluteCoords(
|
||||||
? LinearElementEditor.pointFromAbsoluteCoords(
|
element,
|
||||||
element,
|
pointFrom<GlobalPoint>(sceneCoords.x, sceneCoords.y),
|
||||||
sceneCoords
|
elementsMap,
|
||||||
? pointFrom<GlobalPoint>(sceneCoords.x, sceneCoords.y)
|
),
|
||||||
: LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
|
||||||
element,
|
|
||||||
-1,
|
|
||||||
arrayToMap(newElements),
|
|
||||||
),
|
|
||||||
elementsMap,
|
|
||||||
)
|
|
||||||
: element.points[index],
|
|
||||||
draggedPoints: !newArrow,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user