Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
e2cc961c76
commit
bac20fa641
@ -1514,20 +1514,13 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
isExistingElement?: boolean;
|
||||
},
|
||||
) {
|
||||
const resetSelection = () => {
|
||||
this.setState({
|
||||
draggingElement: null,
|
||||
editingElement: null,
|
||||
});
|
||||
};
|
||||
|
||||
const updateElement = (text: string) => {
|
||||
const updateElement = (text: string, isDeleted = false) => {
|
||||
globalSceneState.replaceAllElements([
|
||||
...globalSceneState.getElementsIncludingDeleted().map((_element) => {
|
||||
if (_element.id === element.id && isTextElement(_element)) {
|
||||
return updateTextElement(_element, {
|
||||
text,
|
||||
isDeleted: !text.trim(),
|
||||
isDeleted,
|
||||
});
|
||||
}
|
||||
return _element;
|
||||
@ -1551,25 +1544,27 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
||||
updateElement(text);
|
||||
}),
|
||||
onSubmit: withBatchedUpdates((text) => {
|
||||
updateElement(text);
|
||||
this.setState((prevState) => ({
|
||||
selectedElementIds: {
|
||||
...prevState.selectedElementIds,
|
||||
[element.id]: true,
|
||||
},
|
||||
}));
|
||||
const isDeleted = !text.trim();
|
||||
updateElement(text, isDeleted);
|
||||
if (!isDeleted) {
|
||||
this.setState((prevState) => ({
|
||||
selectedElementIds: {
|
||||
...prevState.selectedElementIds,
|
||||
[element.id]: true,
|
||||
},
|
||||
}));
|
||||
}
|
||||
if (!isDeleted || isExistingElement) {
|
||||
history.resumeRecording();
|
||||
}
|
||||
|
||||
this.setState({
|
||||
draggingElement: null,
|
||||
editingElement: null,
|
||||
});
|
||||
if (this.state.elementLocked) {
|
||||
setCursorForShape(this.state.elementType);
|
||||
}
|
||||
history.resumeRecording();
|
||||
resetSelection();
|
||||
}),
|
||||
onCancel: withBatchedUpdates(() => {
|
||||
updateElement("");
|
||||
if (isExistingElement) {
|
||||
history.resumeRecording();
|
||||
}
|
||||
resetSelection();
|
||||
}),
|
||||
});
|
||||
// deselect all other elements when inserting text
|
||||
|
@ -32,14 +32,12 @@ export const textWysiwyg = ({
|
||||
zoom,
|
||||
onChange,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
getViewportCoords,
|
||||
}: {
|
||||
id: ExcalidrawElement["id"];
|
||||
zoom: number;
|
||||
onChange?: (text: string) => void;
|
||||
onSubmit: (text: string) => void;
|
||||
onCancel: () => void;
|
||||
getViewportCoords: (x: number, y: number) => [number, number];
|
||||
}) => {
|
||||
function updateWysiwygStyle() {
|
||||
@ -129,11 +127,7 @@ export const textWysiwyg = ({
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (editable.value) {
|
||||
onSubmit(normalizeText(editable.value));
|
||||
} else {
|
||||
onCancel();
|
||||
}
|
||||
onSubmit(normalizeText(editable.value));
|
||||
cleanup();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user