Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/reactComponents/TabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export const TabContent = React.forwardRef<TabContentRef, TabContentProps>(({
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]);
Expand Down
10 changes: 6 additions & 4 deletions src/reactComponents/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ export function Component(props: TabsProps): React.JSX.Element {
const tabContentRefs = React.useRef<Map<string, TabContentRef>>(new Map());

/** Handles tab change and updates current module. */
const handleTabChange = (key: string): void => {
const handleTabChange = async (key: string): Promise<void> => {
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);
Expand Down