codeview / codeedit commands working (#17)

* server is setting 'mode' linestate to 'view' or 'edit'.  this change sets the editor in readonly mode based on this flag.  (requires the new build of prompt-server)

* apply prettier
This commit is contained in:
sawka 2023-09-07 13:01:07 -07:00 committed by GitHub
parent e78ea62932
commit 660795ea8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -202,16 +202,26 @@ class SourceCodeRenderer extends React.Component<
setEditorHeight = () => {
const fullWindowHeight = this.props.opts.maxSize.height;
let _editorHeight = fullWindowHeight;
if (this.props.readOnly || this.state.isClosed) {
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);
}
this.setState({ editorHeight: _editorHeight }, () => this.props.scrollToBringIntoViewport());
};
getAllowEditing(): boolean {
let lineState = this.props.lineState;
let mode = lineState["mode"] || "view";
if (mode == "view") {
return false;
}
return !(this.props.readOnly || this.state.isClosed);
}
render() {
const { opts, exitcode, readOnly } = this.props;
const { selectedLanguage, code, isSave, isClosed } = this.state;
const { opts, exitcode } = this.props;
const { selectedLanguage, code, isSave } = this.state;
if (code == null)
return <div className="renderer-container code-renderer" style={{ height: this.props.savedHeight }} />;
@ -230,6 +240,7 @@ class SourceCodeRenderer extends React.Component<
</div>
);
let allowEditing = this.getAllowEditing();
return (
<div className="renderer-container code-renderer">
<div className="scroller" style={{ maxHeight: opts.maxSize.height, paddingBottom: "15px" }}>
@ -243,7 +254,7 @@ class SourceCodeRenderer extends React.Component<
scrollBeyondLastLine: false,
fontSize: GlobalModel.termFontSize.get(),
fontFamily: "JetBrains Mono",
readOnly: readOnly || isClosed,
readOnly: !allowEditing,
}}
onChange={this.handleEditorChange}
/>
@ -261,7 +272,7 @@ class SourceCodeRenderer extends React.Component<
</option>
))}
</select>
{!readOnly && !isClosed && (
{allowEditing && (
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem", marginLeft: "-18px" }}>
<div
onClick={this.doSave}
@ -273,7 +284,7 @@ class SourceCodeRenderer extends React.Component<
</div>
</div>
)}
{!readOnly && !isClosed && (
{allowEditing && (
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem", marginLeft: "-18px" }}>
<div
onClick={this.doClose}