Skip to content

Commit

Permalink
PE-74 and PE-54
Browse files Browse the repository at this point in the history
 pass isSelected (to prevent multiple scrolling).  also fix initial editorheight to prevent jitter (#19)
  • Loading branch information
sawka authored Sep 7, 2023
1 parent 660795e commit aaaf7af
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/fullrenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FullRenderer extends React.Component<
plugin: RendererPluginType;
onHeightChange: () => void;
initParams: RendererModelInitializeParams;
isSelected: boolean;
},
{}
> {
Expand Down
2 changes: 2 additions & 0 deletions src/linecomps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ class LineCmd extends React.Component<
onHeightChange={this.handleHeightChange}
initParams={this.makeRendererModelInitializeParams()}
scrollToBringIntoViewport={this.scrollToBringIntoViewport}
isSelected={isSelected}
/>
</If>
<If condition={rendererPlugin != null && rendererPlugin.rendererType == "full"}>
Expand All @@ -776,6 +777,7 @@ class LineCmd extends React.Component<
plugin={rendererPlugin}
onHeightChange={this.handleHeightChange}
initParams={this.makeRendererModelInitializeParams()}
isSelected={isSelected}
/>
</If>
<If condition={cmd.getRtnState()}>
Expand Down
6 changes: 5 additions & 1 deletion src/prompt.less
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ input[type="checkbox"] {
}

.renderer-container.code-renderer {
margin-top: 10px;
.scroller {
padding-top: 10px;
padding-bottom: 15px;
}

.monaco-editor .monaco-editor-background {
background-color: rgba(255, 255, 255, 0.075) !important;
}
Expand Down
4 changes: 3 additions & 1 deletion src/simplerenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class SimpleBlobRenderer extends React.Component<
onHeightChange: () => void;
initParams: RendererModelInitializeParams;
scrollToBringIntoViewport: () => void;
isSelected: boolean;
},
{}
> {
Expand Down Expand Up @@ -264,7 +265,7 @@ class SimpleBlobRenderer extends React.Component<
let simpleModel = model as SimpleBlobRendererModel;
let { festate, cmdstr, exitcode } = this.props.initParams.rawCmd;
return (
<div ref={this.wrapperDivRef}>
<div ref={this.wrapperDivRef} className="sr-wrapper">
<Comp
cwd={festate.cwd}
cmdstr={cmdstr}
Expand All @@ -277,6 +278,7 @@ class SimpleBlobRenderer extends React.Component<
opts={simpleModel.opts}
savedHeight={simpleModel.savedHeight}
scrollToBringIntoViewport={this.props.scrollToBringIntoViewport}
isSelected={this.props.isSelected}
/>
</div>
);
Expand Down
15 changes: 11 additions & 4 deletions src/view/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SourceCodeRenderer extends React.Component<
savedHeight: number;
scrollToBringIntoViewport: () => void;
lineState: LineStateType;
isSelected: boolean;
},
{
code: string;
Expand All @@ -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,
};
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -243,7 +250,7 @@ class SourceCodeRenderer extends React.Component<
let allowEditing = this.getAllowEditing();
return (
<div className="renderer-container code-renderer">
<div className="scroller" style={{ maxHeight: opts.maxSize.height, paddingBottom: "15px" }}>
<div className="scroller" style={{ maxHeight: opts.maxSize.height }}>
<Editor
theme="hc-black"
height={this.state.editorHeight}
Expand Down

0 comments on commit aaaf7af

Please # to comment.