diff --git a/src/reactComponents/TabContent.tsx b/src/reactComponents/TabContent.tsx index 8c665e6f..296cebae 100644 --- a/src/reactComponents/TabContent.tsx +++ b/src/reactComponents/TabContent.tsx @@ -86,7 +86,11 @@ export const TabContent = React.forwardRef(({ React.useImperativeHandle(ref, () => ({ saveModule: async () => { if (editorInstance) { - await editorInstance.saveModule(); + const moduleContentText = await editorInstance.saveModule(); + // Update modulePathToContentText. + // modulePathToContentText is passed to Editor.makeCurrent so the active editor will know + // about changes to other modules. + modulePathToContentText[modulePath] = moduleContentText; } }, }), [editorInstance]); diff --git a/src/reactComponents/Tabs.tsx b/src/reactComponents/Tabs.tsx index 7adfce1b..ce3600fb 100644 --- a/src/reactComponents/Tabs.tsx +++ b/src/reactComponents/Tabs.tsx @@ -84,15 +84,17 @@ export function Component(props: TabsProps): React.JSX.Element { const tabContentRefs = React.useRef>(new Map()); /** Handles tab change and updates current module. */ - const handleTabChange = (key: string): void => { + const handleTabChange = async (key: string): Promise => { if (key !== activeKey) { - // Save the tab we are changing away from (async, but don't wait) + // Save the tab we are changing away from. Wait for the save to complete before changing tabs. const currentTabRef = tabContentRefs.current.get(activeKey); if (currentTabRef) { - currentTabRef.saveModule().catch((error) => { + try { + await currentTabRef.saveModule(); + } catch(error) { console.error('Error saving module on tab switch:', error); props.setAlertErrorMessage(t('FAILED_TO_SAVE_MODULE')); - }); + } } } setActiveKey(key);