@@ -5,6 +5,8 @@ import PreferencesContext, {
55 initialPreferences ,
66 type Preferences ,
77 type AlertMessageIdentifier ,
8+ type EditorStateForProject ,
9+ type EditorStateForProjectUpdate ,
810} from './PreferencesContext' ;
911import optionalRequire from '../../Utils/OptionalRequire' ;
1012import { getIDEVersion } from '../../Version' ;
@@ -21,7 +23,6 @@ import { type EditorMosaicNode } from '../../UI/EditorMosaic';
2123import { type FileMetadataAndStorageProviderName } from '../../ProjectsStorage' ;
2224import defaultShortcuts from '../../KeyboardShortcuts/DefaultShortcuts' ;
2325import { type CommandName } from '../../CommandPalette/CommandsList' ;
24- import { type EditorTabsPersistedState } from '../EditorTabs/EditorTabsHandler' ;
2526import {
2627 getBrowserLanguageOrLocale ,
2728 setLanguageInDOM ,
@@ -1249,24 +1250,54 @@ export default class PreferencesProvider extends React.Component<Props, State> {
12491250 }
12501251
12511252 _getEditorStateForProject ( projectId : string ) : any {
1252- return this . state . values . editorStateByProject [ projectId ] ;
1253+ const editorState = this . state . values . editorStateByProject [ projectId ] ;
1254+ if ( ! editorState ) return null ;
1255+
1256+ return {
1257+ editorTabs : editorState . editorTabs == null ? null : editorState . editorTabs ,
1258+ propertiesPanelScroll : editorState . propertiesPanelScroll || { } ,
1259+ } ;
12531260 }
12541261
12551262 _setEditorStateForProject (
12561263 projectId : string ,
1257- editorState ?: { | editorTabs : EditorTabsPersistedState | }
1264+ editorState : EditorStateForProjectUpdate | null
12581265 ) {
12591266 this . setState (
1260- state => ( {
1261- values : {
1262- ...state . values ,
1263- editorStateByProject : {
1264- ...state . values . editorStateByProject ,
1265- // $FlowFixMe[incompatible-type]
1266- [ projectId ] : editorState ,
1267+ state => {
1268+ const nextEditorStateByProject = {
1269+ ...state . values . editorStateByProject ,
1270+ } ;
1271+
1272+ if ( editorState === null ) {
1273+ delete nextEditorStateByProject [ projectId ] ;
1274+ } else {
1275+ const previousEditorState = state . values . editorStateByProject [ projectId ] || {
1276+ editorTabs : null ,
1277+ propertiesPanelScroll : { } ,
1278+ } ;
1279+ const mergedEditorState : EditorStateForProject = {
1280+ ...previousEditorState ,
1281+ ...editorState ,
1282+ } ;
1283+
1284+ if (
1285+ mergedEditorState . editorTabs === null &&
1286+ Object . keys ( mergedEditorState . propertiesPanelScroll ) . length === 0
1287+ ) {
1288+ delete nextEditorStateByProject [ projectId ] ;
1289+ } else {
1290+ nextEditorStateByProject [ projectId ] = mergedEditorState ;
1291+ }
1292+ }
1293+
1294+ return {
1295+ values : {
1296+ ...state . values ,
1297+ editorStateByProject : nextEditorStateByProject ,
12671298 } ,
1268- } ,
1269- } ) ,
1299+ } ;
1300+ } ,
12701301 ( ) => this . _persistValuesToLocalStorage ( this . state )
12711302 ) ;
12721303 }
0 commit comments