From 4886cf4fd3c0bbf917505af9d7d4393832749244 Mon Sep 17 00:00:00 2001 From: D8H Date: Fri, 24 May 2024 16:39:11 +0200 Subject: [PATCH] Fix the event height after adding local variables (#6590) - Also fix local variable dialog cancel. - Don't show in changelog --- newIDE/app/src/EventsSheet/index.js | 35 +++++++------ .../src/VariablesList/LocalVariablesDialog.js | 51 +++++++++++++++++++ 2 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 newIDE/app/src/VariablesList/LocalVariablesDialog.js diff --git a/newIDE/app/src/EventsSheet/index.js b/newIDE/app/src/EventsSheet/index.js index 8c79da4ad8..1356f6072b 100644 --- a/newIDE/app/src/EventsSheet/index.js +++ b/newIDE/app/src/EventsSheet/index.js @@ -114,7 +114,7 @@ import { } from '../MainFrame/ResourcesWatcher'; import { insertInVariablesContainer } from '../Utils/VariablesUtils'; import { ProjectScopedContainersAccessor } from '../InstructionOrExpression/EventsScope.flow'; -import VariablesEditorDialog from '../VariablesList/VariablesEditorDialog'; +import LocalVariablesDialog from '../VariablesList/LocalVariablesDialog'; const gd: libGDevelop = global.gd; @@ -2102,9 +2102,8 @@ export class EventsSheetComponentWithoutHandle extends React.Component< /> )} {this.state.editedVariable && ( - Local variables} open onCancel={() => this.setState({ @@ -2112,23 +2111,27 @@ export class EventsSheetComponentWithoutHandle extends React.Component< }) } onApply={() => { + const eventContext = this.state.editedVariable + ? this.state.editedVariable.eventContext + : null; this.setState({ editedVariable: null, }); - if (this._eventsTree) - this._eventsTree.forceEventsUpdate(); + if (this._eventsTree && eventContext) { + this._eventsTree.forceEventsUpdate(() => { + const positions = this._getChangedEventRows([ + eventContext.event, + ]); + this._saveChangesToHistory('ADD', { + positionsBeforeAction: positions, + positionAfterAction: positions, + }); + }); + } }} - tabs={[ - { - id: 'local-variables', - label: '', - variablesContainer: this.state.editedVariable - .variablesContainer, - onComputeAllVariableNames: () => [], - }, - ]} - helpPagePath={'/all-features/variables/local-variables'} - preventRefactoringToDeleteInstructions + variablesContainer={ + this.state.editedVariable.variablesContainer + } initiallySelectedVariableName={ this.state.editedVariable.variableName } diff --git a/newIDE/app/src/VariablesList/LocalVariablesDialog.js b/newIDE/app/src/VariablesList/LocalVariablesDialog.js new file mode 100644 index 0000000000..664c6e2a36 --- /dev/null +++ b/newIDE/app/src/VariablesList/LocalVariablesDialog.js @@ -0,0 +1,51 @@ +// @flow +import * as React from 'react'; +import { Trans } from '@lingui/macro'; +import VariablesEditorDialog from './VariablesEditorDialog'; + +type Props = {| + open: boolean, + project: gdProject, + variablesContainer: gdVariablesContainer, + onApply: (selectedVariableName: string | null) => void, + onCancel: () => void, + initiallySelectedVariableName: string, +|}; + +const LocalVariablesDialog = ({ + project, + variablesContainer, + open, + onCancel, + onApply, + initiallySelectedVariableName, +}: Props) => { + const tabs = React.useMemo( + () => [ + { + id: 'local-variables', + label: '', + variablesContainer, + onComputeAllVariableNames: () => [], + }, + ], + [variablesContainer] + ); + + return ( + Local variables} + tabs={tabs} + helpPagePath={'/all-features/variables/local-variables'} + preventRefactoringToDeleteInstructions + id="local-variables-dialog" + initiallySelectedVariableName={initiallySelectedVariableName} + /> + ); +}; + +export default LocalVariablesDialog;