+
);
diff --git a/src/view/code.tsx b/src/view/code.tsx
index d8e2b511..18f83e8e 100644
--- a/src/view/code.tsx
+++ b/src/view/code.tsx
@@ -26,6 +26,7 @@ class SourceCodeRenderer extends React.Component<
savedHeight: number;
scrollToBringIntoViewport: () => void;
lineState: LineStateType;
+ isSelected: boolean;
},
{
code: string;
@@ -51,13 +52,14 @@ class SourceCodeRenderer extends React.Component<
constructor(props) {
super(props);
this.monacoEditor = null;
+ const editorHeight = Math.max(props.savedHeight - 25, 0); // must subtract the padding/margin to get the real editorHeight
this.state = {
code: null,
languages: [],
selectedLanguage: "",
isSave: false,
isClosed: false,
- editorHeight: props.savedHeight,
+ editorHeight: editorHeight,
message: null,
};
}
@@ -205,9 +207,14 @@ class SourceCodeRenderer extends React.Component<
let allowEditing = this.getAllowEditing();
if (!allowEditing) {
const noOfLines = Math.max(this.state.code.split("\n").length, 5);
- _editorHeight = Math.min(noOfLines * GlobalModel.termFontSize.get() * 1.5 + 10, fullWindowHeight);
+ const lineHeight = Math.ceil(GlobalModel.termFontSize.get() * 1.5);
+ _editorHeight = Math.min(noOfLines * lineHeight + 10, fullWindowHeight);
}
- this.setState({ editorHeight: _editorHeight }, () => this.props.scrollToBringIntoViewport());
+ this.setState({ editorHeight: _editorHeight }, () => {
+ if (this.props.isSelected) {
+ this.props.scrollToBringIntoViewport();
+ }
+ });
};
getAllowEditing(): boolean {
@@ -243,7 +250,7 @@ class SourceCodeRenderer extends React.Component<
let allowEditing = this.getAllowEditing();
return (