Choosing color before entering text does not update the swatch (Fixes #1897) (#1915)

Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Mohammed Salman 2020-07-14 14:56:45 +03:00 committed by GitHub
parent e2cc961c76
commit bac20fa641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 32 deletions

View File

@ -1514,20 +1514,13 @@ class App extends React.Component<ExcalidrawProps, AppState> {
isExistingElement?: boolean; isExistingElement?: boolean;
}, },
) { ) {
const resetSelection = () => { const updateElement = (text: string, isDeleted = false) => {
this.setState({
draggingElement: null,
editingElement: null,
});
};
const updateElement = (text: string) => {
globalSceneState.replaceAllElements([ globalSceneState.replaceAllElements([
...globalSceneState.getElementsIncludingDeleted().map((_element) => { ...globalSceneState.getElementsIncludingDeleted().map((_element) => {
if (_element.id === element.id && isTextElement(_element)) { if (_element.id === element.id && isTextElement(_element)) {
return updateTextElement(_element, { return updateTextElement(_element, {
text, text,
isDeleted: !text.trim(), isDeleted,
}); });
} }
return _element; return _element;
@ -1551,25 +1544,27 @@ class App extends React.Component<ExcalidrawProps, AppState> {
updateElement(text); updateElement(text);
}), }),
onSubmit: withBatchedUpdates((text) => { onSubmit: withBatchedUpdates((text) => {
updateElement(text); const isDeleted = !text.trim();
this.setState((prevState) => ({ updateElement(text, isDeleted);
selectedElementIds: { if (!isDeleted) {
...prevState.selectedElementIds, this.setState((prevState) => ({
[element.id]: true, selectedElementIds: {
}, ...prevState.selectedElementIds,
})); [element.id]: true,
},
}));
}
if (!isDeleted || isExistingElement) {
history.resumeRecording();
}
this.setState({
draggingElement: null,
editingElement: null,
});
if (this.state.elementLocked) { if (this.state.elementLocked) {
setCursorForShape(this.state.elementType); setCursorForShape(this.state.elementType);
} }
history.resumeRecording();
resetSelection();
}),
onCancel: withBatchedUpdates(() => {
updateElement("");
if (isExistingElement) {
history.resumeRecording();
}
resetSelection();
}), }),
}); });
// deselect all other elements when inserting text // deselect all other elements when inserting text

View File

@ -32,14 +32,12 @@ export const textWysiwyg = ({
zoom, zoom,
onChange, onChange,
onSubmit, onSubmit,
onCancel,
getViewportCoords, getViewportCoords,
}: { }: {
id: ExcalidrawElement["id"]; id: ExcalidrawElement["id"];
zoom: number; zoom: number;
onChange?: (text: string) => void; onChange?: (text: string) => void;
onSubmit: (text: string) => void; onSubmit: (text: string) => void;
onCancel: () => void;
getViewportCoords: (x: number, y: number) => [number, number]; getViewportCoords: (x: number, y: number) => [number, number];
}) => { }) => {
function updateWysiwygStyle() { function updateWysiwygStyle() {
@ -129,11 +127,7 @@ export const textWysiwyg = ({
}; };
const handleSubmit = () => { const handleSubmit = () => {
if (editable.value) { onSubmit(normalizeText(editable.value));
onSubmit(normalizeText(editable.value));
} else {
onCancel();
}
cleanup(); cleanup();
}; };