fix deleting multi-point elem during edit (#1892)
This commit is contained in:
parent
51a8ab65f3
commit
6e357c0291
@ -52,15 +52,19 @@ function handleGroupEditingState(
|
|||||||
export const actionDeleteSelected = register({
|
export const actionDeleteSelected = register({
|
||||||
name: "deleteSelectedElements",
|
name: "deleteSelectedElements",
|
||||||
perform: (elements, appState) => {
|
perform: (elements, appState) => {
|
||||||
if (
|
if (appState.editingLinearElement) {
|
||||||
appState.editingLinearElement?.activePointIndex != null &&
|
const { elementId, activePointIndex } = appState.editingLinearElement;
|
||||||
appState.editingLinearElement?.activePointIndex > -1
|
|
||||||
) {
|
|
||||||
const { elementId } = appState.editingLinearElement;
|
|
||||||
const element = LinearElementEditor.getElement(elementId);
|
const element = LinearElementEditor.getElement(elementId);
|
||||||
if (element) {
|
if (!element) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
// case: no point selected → delete whole element
|
||||||
|
activePointIndex == null ||
|
||||||
|
activePointIndex === -1 ||
|
||||||
// case: deleting last point
|
// case: deleting last point
|
||||||
if (element.points.length < 2) {
|
element.points.length < 2
|
||||||
|
) {
|
||||||
const nextElements = elements.filter((el) => el.id !== element.id);
|
const nextElements = elements.filter((el) => el.id !== element.id);
|
||||||
const nextAppState = handleGroupEditingState(appState, nextElements);
|
const nextAppState = handleGroupEditingState(appState, nextElements);
|
||||||
|
|
||||||
@ -74,11 +78,7 @@ export const actionDeleteSelected = register({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearElementEditor.movePoint(
|
LinearElementEditor.movePoint(element, activePointIndex, "delete");
|
||||||
element,
|
|
||||||
appState.editingLinearElement.activePointIndex,
|
|
||||||
"delete",
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements: elements,
|
elements: elements,
|
||||||
@ -86,16 +86,12 @@ export const actionDeleteSelected = register({
|
|||||||
...appState,
|
...appState,
|
||||||
editingLinearElement: {
|
editingLinearElement: {
|
||||||
...appState.editingLinearElement,
|
...appState.editingLinearElement,
|
||||||
activePointIndex:
|
activePointIndex: activePointIndex > 0 ? activePointIndex - 1 : 0,
|
||||||
appState.editingLinearElement.activePointIndex > 0
|
|
||||||
? appState.editingLinearElement.activePointIndex - 1
|
|
||||||
: 0,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let {
|
let {
|
||||||
elements: nextElements,
|
elements: nextElements,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user