Reset selectedElementIds when deleting selected elements (#875)

This commit is contained in:
Pete Hunt 2020-03-08 14:10:42 -07:00 committed by GitHub
parent ccbbdb75a6
commit c89584832d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -9,9 +9,17 @@ import { register } from "./register";
export const actionDeleteSelected = register({ export const actionDeleteSelected = register({
name: "deleteSelectedElements", name: "deleteSelectedElements",
perform: (elements, appState) => { perform: (elements, appState) => {
const {
elements: nextElements,
appState: nextAppState,
} = deleteSelectedElements(elements, appState);
return { return {
elements: deleteSelectedElements(elements, appState), elements: nextElements,
appState: { ...appState, elementType: "selection", multiElement: null }, appState: {
...nextAppState,
elementType: "selection",
multiElement: null,
},
}; };
}, },
contextItemLabel: "labels.delete", contextItemLabel: "labels.delete",

View File

@ -180,9 +180,13 @@ export class App extends React.Component<any, AppState> {
return; return;
} }
copyToAppClipboard(elements, this.state); copyToAppClipboard(elements, this.state);
elements = deleteSelectedElements(elements, this.state); const { elements: nextElements, appState } = deleteSelectedElements(
elements,
this.state,
);
elements = nextElements;
history.resumeRecording(); history.resumeRecording();
this.setState({}); this.setState({ ...appState });
event.preventDefault(); event.preventDefault();
}; };
private onCopy = (event: ClipboardEvent) => { private onCopy = (event: ClipboardEvent) => {

View File

@ -34,7 +34,13 @@ export function deleteSelectedElements(
elements: readonly ExcalidrawElement[], elements: readonly ExcalidrawElement[],
appState: AppState, appState: AppState,
) { ) {
return elements.filter(el => !appState.selectedElementIds[el.id]); return {
elements: elements.filter(el => !appState.selectedElementIds[el.id]),
appState: {
...appState,
selectedElementIds: {},
},
};
} }
export function getSelectedIndices( export function getSelectedIndices(