Skip to content

Commit

Permalink
fix: output panel didn't save data when switching panels (#252)
Browse files Browse the repository at this point in the history
* fix: output panel didn't save data when switching panels

* fix: improve output editor instance

* fix: improve append output via updateOutput
  • Loading branch information
mortalYoung authored Jul 19, 2021
1 parent b482f8f commit 92b7321
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/model/workbench/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ export function builtInOutputPanel() {
data: '',
};

function onUpdateEditorIns(editorInstance: IStandaloneCodeEditor) {
outputPane.outputEditorInstance = editorInstance;
function onUpdateEditorIns(
editorInstance: IStandaloneCodeEditor,
item: IOutput
) {
item.outputEditorInstance = editorInstance;
}

outputPane.renderPane = (item) => (
<Output onUpdateEditorIns={onUpdateEditorIns} {...item} />
<Output
onUpdateEditorIns={(instance) => onUpdateEditorIns(instance, item)}
{...item}
/>
);

return outputPane;
Expand Down
4 changes: 4 additions & 0 deletions src/services/workbench/panelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class PanelService extends Component<IPanel> implements IPanelService {

public appendOutput(content: string): void {
const outputValue = this.outputEditorInstance?.getValue();
this.updateOutput({
id: PANEL_OUTPUT,
data: outputValue + content,
});
this.outputEditorInstance?.setValue(outputValue + content);
}

Expand Down
9 changes: 8 additions & 1 deletion src/workbench/panel/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { MonacoEditor } from 'mo/components/monaco';
const defaultClassName = prefixClaName('output');

function Output(props: IOutput) {
const { id, data = '', onUpdateEditorIns } = props;
const { id, data = '', onUpdateEditorIns, outputEditorInstance } = props;
const editorDidMount = React.useRef(false);

if (!editorDidMount.current && outputEditorInstance) {
outputEditorInstance.dispose();
}

return (
<div className={defaultClassName}>
<MonacoEditor
Expand All @@ -23,6 +29,7 @@ function Output(props: IOutput) {
}}
editorInstanceRef={(editorInstance) => {
onUpdateEditorIns?.(editorInstance);
editorDidMount.current = true;
}}
/>
</div>
Expand Down

0 comments on commit 92b7321

Please sign in to comment.