Skip to content

Commit af999b2

Browse files
authored
Modified Tabs so it waits for the saveModule to finish before switching tabs. (#312)
Modified TabContent so when a module is saved, it updates modulePathToContentText.
1 parent f1fa8f0 commit af999b2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/reactComponents/TabContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ export const TabContent = React.forwardRef<TabContentRef, TabContentProps>(({
8686
React.useImperativeHandle(ref, () => ({
8787
saveModule: async () => {
8888
if (editorInstance) {
89-
await editorInstance.saveModule();
89+
const moduleContentText = await editorInstance.saveModule();
90+
// Update modulePathToContentText.
91+
// modulePathToContentText is passed to Editor.makeCurrent so the active editor will know
92+
// about changes to other modules.
93+
modulePathToContentText[modulePath] = moduleContentText;
9094
}
9195
},
9296
}), [editorInstance]);

src/reactComponents/Tabs.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ export function Component(props: TabsProps): React.JSX.Element {
8484
const tabContentRefs = React.useRef<Map<string, TabContentRef>>(new Map());
8585

8686
/** Handles tab change and updates current module. */
87-
const handleTabChange = (key: string): void => {
87+
const handleTabChange = async (key: string): Promise<void> => {
8888
if (key !== activeKey) {
89-
// Save the tab we are changing away from (async, but don't wait)
89+
// Save the tab we are changing away from. Wait for the save to complete before changing tabs.
9090
const currentTabRef = tabContentRefs.current.get(activeKey);
9191
if (currentTabRef) {
92-
currentTabRef.saveModule().catch((error) => {
92+
try {
93+
await currentTabRef.saveModule();
94+
} catch(error) {
9395
console.error('Error saving module on tab switch:', error);
9496
props.setAlertErrorMessage(t('FAILED_TO_SAVE_MODULE'));
95-
});
97+
}
9698
}
9799
}
98100
setActiveKey(key);

0 commit comments

Comments
 (0)