mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: robust state.editingFrame
teardown (#8941)
This commit is contained in:
parent
606ac6c743
commit
873698a1a2
2 changed files with 16 additions and 7 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue