Skip to content

Commit 92b7321

Browse files
authored
fix: output panel didn't save data when switching panels (#252)
* fix: output panel didn't save data when switching panels * fix: improve output editor instance * fix: improve append output via updateOutput
1 parent b482f8f commit 92b7321

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/model/workbench/panel.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ export function builtInOutputPanel() {
3939
data: '',
4040
};
4141

42-
function onUpdateEditorIns(editorInstance: IStandaloneCodeEditor) {
43-
outputPane.outputEditorInstance = editorInstance;
42+
function onUpdateEditorIns(
43+
editorInstance: IStandaloneCodeEditor,
44+
item: IOutput
45+
) {
46+
item.outputEditorInstance = editorInstance;
4447
}
4548

4649
outputPane.renderPane = (item) => (
47-
<Output onUpdateEditorIns={onUpdateEditorIns} {...item} />
50+
<Output
51+
onUpdateEditorIns={(instance) => onUpdateEditorIns(instance, item)}
52+
{...item}
53+
/>
4854
);
4955

5056
return outputPane;

src/services/workbench/panelService.ts

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export class PanelService extends Component<IPanel> implements IPanelService {
102102

103103
public appendOutput(content: string): void {
104104
const outputValue = this.outputEditorInstance?.getValue();
105+
this.updateOutput({
106+
id: PANEL_OUTPUT,
107+
data: outputValue + content,
108+
});
105109
this.outputEditorInstance?.setValue(outputValue + content);
106110
}
107111

src/workbench/panel/output.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { MonacoEditor } from 'mo/components/monaco';
66
const defaultClassName = prefixClaName('output');
77

88
function Output(props: IOutput) {
9-
const { id, data = '', onUpdateEditorIns } = props;
9+
const { id, data = '', onUpdateEditorIns, outputEditorInstance } = props;
10+
const editorDidMount = React.useRef(false);
11+
12+
if (!editorDidMount.current && outputEditorInstance) {
13+
outputEditorInstance.dispose();
14+
}
15+
1016
return (
1117
<div className={defaultClassName}>
1218
<MonacoEditor
@@ -23,6 +29,7 @@ function Output(props: IOutput) {
2329
}}
2430
editorInstanceRef={(editorInstance) => {
2531
onUpdateEditorIns?.(editorInstance);
32+
editorDidMount.current = true;
2633
}}
2734
/>
2835
</div>

0 commit comments

Comments
 (0)