Skip to content

Commit aaaf7af

Browse files
authored
PE-74 and PE-54
pass isSelected (to prevent multiple scrolling). also fix initial editorheight to prevent jitter (#19)
1 parent 660795e commit aaaf7af

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

src/fullrenderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class FullRenderer extends React.Component<
3333
plugin: RendererPluginType;
3434
onHeightChange: () => void;
3535
initParams: RendererModelInitializeParams;
36+
isSelected: boolean;
3637
},
3738
{}
3839
> {

src/linecomps.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ class LineCmd extends React.Component<
767767
onHeightChange={this.handleHeightChange}
768768
initParams={this.makeRendererModelInitializeParams()}
769769
scrollToBringIntoViewport={this.scrollToBringIntoViewport}
770+
isSelected={isSelected}
770771
/>
771772
</If>
772773
<If condition={rendererPlugin != null && rendererPlugin.rendererType == "full"}>
@@ -776,6 +777,7 @@ class LineCmd extends React.Component<
776777
plugin={rendererPlugin}
777778
onHeightChange={this.handleHeightChange}
778779
initParams={this.makeRendererModelInitializeParams()}
780+
isSelected={isSelected}
779781
/>
780782
</If>
781783
<If condition={cmd.getRtnState()}>

src/prompt.less

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ input[type="checkbox"] {
249249
}
250250

251251
.renderer-container.code-renderer {
252-
margin-top: 10px;
252+
.scroller {
253+
padding-top: 10px;
254+
padding-bottom: 15px;
255+
}
256+
253257
.monaco-editor .monaco-editor-background {
254258
background-color: rgba(255, 255, 255, 0.075) !important;
255259
}

src/simplerenderer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class SimpleBlobRenderer extends React.Component<
176176
onHeightChange: () => void;
177177
initParams: RendererModelInitializeParams;
178178
scrollToBringIntoViewport: () => void;
179+
isSelected: boolean;
179180
},
180181
{}
181182
> {
@@ -264,7 +265,7 @@ class SimpleBlobRenderer extends React.Component<
264265
let simpleModel = model as SimpleBlobRendererModel;
265266
let { festate, cmdstr, exitcode } = this.props.initParams.rawCmd;
266267
return (
267-
<div ref={this.wrapperDivRef}>
268+
<div ref={this.wrapperDivRef} className="sr-wrapper">
268269
<Comp
269270
cwd={festate.cwd}
270271
cmdstr={cmdstr}
@@ -277,6 +278,7 @@ class SimpleBlobRenderer extends React.Component<
277278
opts={simpleModel.opts}
278279
savedHeight={simpleModel.savedHeight}
279280
scrollToBringIntoViewport={this.props.scrollToBringIntoViewport}
281+
isSelected={this.props.isSelected}
280282
/>
281283
</div>
282284
);

src/view/code.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SourceCodeRenderer extends React.Component<
2626
savedHeight: number;
2727
scrollToBringIntoViewport: () => void;
2828
lineState: LineStateType;
29+
isSelected: boolean;
2930
},
3031
{
3132
code: string;
@@ -51,13 +52,14 @@ class SourceCodeRenderer extends React.Component<
5152
constructor(props) {
5253
super(props);
5354
this.monacoEditor = null;
55+
const editorHeight = Math.max(props.savedHeight - 25, 0); // must subtract the padding/margin to get the real editorHeight
5456
this.state = {
5557
code: null,
5658
languages: [],
5759
selectedLanguage: "",
5860
isSave: false,
5961
isClosed: false,
60-
editorHeight: props.savedHeight,
62+
editorHeight: editorHeight,
6163
message: null,
6264
};
6365
}
@@ -205,9 +207,14 @@ class SourceCodeRenderer extends React.Component<
205207
let allowEditing = this.getAllowEditing();
206208
if (!allowEditing) {
207209
const noOfLines = Math.max(this.state.code.split("\n").length, 5);
208-
_editorHeight = Math.min(noOfLines * GlobalModel.termFontSize.get() * 1.5 + 10, fullWindowHeight);
210+
const lineHeight = Math.ceil(GlobalModel.termFontSize.get() * 1.5);
211+
_editorHeight = Math.min(noOfLines * lineHeight + 10, fullWindowHeight);
209212
}
210-
this.setState({ editorHeight: _editorHeight }, () => this.props.scrollToBringIntoViewport());
213+
this.setState({ editorHeight: _editorHeight }, () => {
214+
if (this.props.isSelected) {
215+
this.props.scrollToBringIntoViewport();
216+
}
217+
});
211218
};
212219

213220
getAllowEditing(): boolean {
@@ -243,7 +250,7 @@ class SourceCodeRenderer extends React.Component<
243250
let allowEditing = this.getAllowEditing();
244251
return (
245252
<div className="renderer-container code-renderer">
246-
<div className="scroller" style={{ maxHeight: opts.maxSize.height, paddingBottom: "15px" }}>
253+
<div className="scroller" style={{ maxHeight: opts.maxSize.height }}>
247254
<Editor
248255
theme="hc-black"
249256
height={this.state.editorHeight}

0 commit comments

Comments
 (0)