clear selection from copied/duplicatated group (#1973)
Co-authored-by: rene_mbp <harryloveslearning@googlemail.com> Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
c06988a202
commit
403e8bd307
@ -10,6 +10,7 @@ import { t } from "../i18n";
|
|||||||
import { getShortcutKey } from "../utils";
|
import { getShortcutKey } from "../utils";
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
import { mutateElement } from "../element/mutateElement";
|
import { mutateElement } from "../element/mutateElement";
|
||||||
|
import { selectGroupsForSelectedElements } from "../groups";
|
||||||
|
|
||||||
export const actionDuplicateSelection = register({
|
export const actionDuplicateSelection = register({
|
||||||
name: "duplicateSelection",
|
name: "duplicateSelection",
|
||||||
@ -50,28 +51,39 @@ export const actionDuplicateSelection = register({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const groupIdMap = new Map();
|
const groupIdMap = new Map();
|
||||||
|
const newElements: ExcalidrawElement[] = [];
|
||||||
|
const finalElements = elements.reduce(
|
||||||
|
(acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
|
||||||
|
if (appState.selectedElementIds[element.id]) {
|
||||||
|
const newElement = duplicateElement(
|
||||||
|
appState.editingGroupId,
|
||||||
|
groupIdMap,
|
||||||
|
element,
|
||||||
|
{
|
||||||
|
x: element.x + 10,
|
||||||
|
y: element.y + 10,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
newElements.push(newElement);
|
||||||
|
return acc.concat([element, newElement]);
|
||||||
|
}
|
||||||
|
return acc.concat(element);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
appState,
|
appState: selectGroupsForSelectedElements(
|
||||||
elements: elements.reduce(
|
{
|
||||||
(acc: Array<ExcalidrawElement>, element: ExcalidrawElement) => {
|
...appState,
|
||||||
if (appState.selectedElementIds[element.id]) {
|
selectedGroupIds: {},
|
||||||
const newElement = duplicateElement(
|
selectedElementIds: newElements.reduce((acc, element) => {
|
||||||
appState.editingGroupId,
|
acc[element.id] = true;
|
||||||
groupIdMap,
|
return acc;
|
||||||
element,
|
}, {} as any),
|
||||||
{
|
|
||||||
x: element.x + 10,
|
|
||||||
y: element.y + 10,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
appState.selectedElementIds[newElement.id] = true;
|
|
||||||
delete appState.selectedElementIds[element.id];
|
|
||||||
return acc.concat([element, newElement]);
|
|
||||||
}
|
|
||||||
return acc.concat(element);
|
|
||||||
},
|
},
|
||||||
[],
|
getNonDeletedElements(finalElements),
|
||||||
),
|
),
|
||||||
|
elements: finalElements,
|
||||||
commitToHistory: true,
|
commitToHistory: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,7 @@ export class ActionManager implements ActionsManagerInterface {
|
|||||||
|
|
||||||
updater: UpdaterFn;
|
updater: UpdaterFn;
|
||||||
|
|
||||||
getAppState: () => AppState;
|
getAppState: () => Readonly<AppState>;
|
||||||
|
|
||||||
getElementsIncludingDeleted: () => readonly ExcalidrawElement[];
|
getElementsIncludingDeleted: () => readonly ExcalidrawElement[];
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ export type ActionResult =
|
|||||||
|
|
||||||
type ActionFn = (
|
type ActionFn = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
appState: AppState,
|
appState: Readonly<AppState>,
|
||||||
formData: any,
|
formData: any,
|
||||||
) => ActionResult;
|
) => ActionResult;
|
||||||
|
|
||||||
|
@ -956,19 +956,25 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||||||
y: element.y + dy - minY,
|
y: element.y + dy - minY,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.scene.replaceAllElements([
|
this.scene.replaceAllElements([
|
||||||
...this.scene.getElementsIncludingDeleted(),
|
...this.scene.getElementsIncludingDeleted(),
|
||||||
...newElements,
|
...newElements,
|
||||||
]);
|
]);
|
||||||
history.resumeRecording();
|
history.resumeRecording();
|
||||||
this.setState({
|
this.setState(
|
||||||
isLibraryOpen: false,
|
selectGroupsForSelectedElements(
|
||||||
selectedElementIds: newElements.reduce((map, element) => {
|
{
|
||||||
map[element.id] = true;
|
...this.state,
|
||||||
return map;
|
isLibraryOpen: false,
|
||||||
}, {} as any),
|
selectedElementIds: newElements.reduce((map, element) => {
|
||||||
});
|
map[element.id] = true;
|
||||||
|
return map;
|
||||||
|
}, {} as any),
|
||||||
|
selectedGroupIds: {},
|
||||||
|
},
|
||||||
|
this.scene.getElements(),
|
||||||
|
),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
private addTextFromPaste(text: any) {
|
private addTextFromPaste(text: any) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user