fix: robust `state.editingFrame` teardown (#8941)

pull/8896/merge
David Luzar 1 month ago committed by GitHub
parent 606ac6c743
commit 873698a1a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1341,8 +1341,18 @@ class App extends React.Component<AppProps, AppState> {
_cache: new Map(),
};
private resetEditingFrame = (frame: ExcalidrawFrameLikeElement | null) => {
if (frame) {
mutateElement(frame, { name: frame.name?.trim() || null });
}
this.setState({ editingFrame: null });
};
private renderFrameNames = () => {
if (!this.state.frameRendering.enabled || !this.state.frameRendering.name) {
if (this.state.editingFrame) {
this.resetEditingFrame(null);
}
return null;
}
@ -1364,6 +1374,9 @@ class App extends React.Component<AppProps, AppState> {
this.scene.getNonDeletedElementsMap(),
)
) {
if (this.state.editingFrame === f.id) {
this.resetEditingFrame(f);
}
// if frame not visible, don't render its name
return null;
}
@ -1375,11 +1388,6 @@ class App extends React.Component<AppProps, AppState> {
const FRAME_NAME_EDIT_PADDING = 6;
const reset = () => {
mutateElement(f, { name: f.name?.trim() || null });
this.setState({ editingFrame: null });
};
let frameNameJSX;
const frameName = getFrameLikeTitle(f);
@ -1397,13 +1405,13 @@ class App extends React.Component<AppProps, AppState> {
});
}}
onFocus={(e) => e.target.select()}
onBlur={() => reset()}
onBlur={() => this.resetEditingFrame(f)}
onKeyDown={(event) => {
// for some inexplicable reason, `onBlur` triggered on ESC
// does not reset `state.editingFrame` despite being called,
// and we need to reset it here as well
if (event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) {
reset();
this.resetEditingFrame(f);
}
}}
style={{

@ -639,6 +639,7 @@ export const restoreAppState = (
gridStep: getNormalizedGridStep(
isFiniteNumber(appState.gridStep) ? appState.gridStep : DEFAULT_GRID_STEP,
),
editingFrame: null,
};
};

Loading…
Cancel
Save