From 660795ea8fcb7ac5548e3ddb954df2335bec9027 Mon Sep 17 00:00:00 2001 From: sawka Date: Thu, 7 Sep 2023 13:01:07 -0700 Subject: [PATCH] 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 --- src/view/code.tsx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/view/code.tsx b/src/view/code.tsx index e7a54d54..d8e2b511 100644 --- a/src/view/code.tsx +++ b/src/view/code.tsx @@ -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
; @@ -230,6 +240,7 @@ class SourceCodeRenderer extends React.Component<
); + let allowEditing = this.getAllowEditing(); return (
@@ -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< ))} - {!readOnly && !isClosed && ( + {allowEditing && (
)} - {!readOnly && !isClosed && ( + {allowEditing && (