mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
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:
parent
e78ea62932
commit
660795ea8f
@ -202,16 +202,26 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
setEditorHeight = () => {
|
setEditorHeight = () => {
|
||||||
const fullWindowHeight = this.props.opts.maxSize.height;
|
const fullWindowHeight = this.props.opts.maxSize.height;
|
||||||
let _editorHeight = fullWindowHeight;
|
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);
|
const noOfLines = Math.max(this.state.code.split("\n").length, 5);
|
||||||
_editorHeight = Math.min(noOfLines * GlobalModel.termFontSize.get() * 1.5 + 10, fullWindowHeight);
|
_editorHeight = Math.min(noOfLines * GlobalModel.termFontSize.get() * 1.5 + 10, fullWindowHeight);
|
||||||
}
|
}
|
||||||
this.setState({ editorHeight: _editorHeight }, () => this.props.scrollToBringIntoViewport());
|
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() {
|
render() {
|
||||||
const { opts, exitcode, readOnly } = this.props;
|
const { opts, exitcode } = this.props;
|
||||||
const { selectedLanguage, code, isSave, isClosed } = this.state;
|
const { selectedLanguage, code, isSave } = this.state;
|
||||||
|
|
||||||
if (code == null)
|
if (code == null)
|
||||||
return <div className="renderer-container code-renderer" style={{ height: this.props.savedHeight }} />;
|
return <div className="renderer-container code-renderer" style={{ height: this.props.savedHeight }} />;
|
||||||
@ -230,6 +240,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let allowEditing = this.getAllowEditing();
|
||||||
return (
|
return (
|
||||||
<div className="renderer-container code-renderer">
|
<div className="renderer-container code-renderer">
|
||||||
<div className="scroller" style={{ maxHeight: opts.maxSize.height, paddingBottom: "15px" }}>
|
<div className="scroller" style={{ maxHeight: opts.maxSize.height, paddingBottom: "15px" }}>
|
||||||
@ -243,7 +254,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
scrollBeyondLastLine: false,
|
scrollBeyondLastLine: false,
|
||||||
fontSize: GlobalModel.termFontSize.get(),
|
fontSize: GlobalModel.termFontSize.get(),
|
||||||
fontFamily: "JetBrains Mono",
|
fontFamily: "JetBrains Mono",
|
||||||
readOnly: readOnly || isClosed,
|
readOnly: !allowEditing,
|
||||||
}}
|
}}
|
||||||
onChange={this.handleEditorChange}
|
onChange={this.handleEditorChange}
|
||||||
/>
|
/>
|
||||||
@ -261,7 +272,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{!readOnly && !isClosed && (
|
{allowEditing && (
|
||||||
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem", marginLeft: "-18px" }}>
|
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem", marginLeft: "-18px" }}>
|
||||||
<div
|
<div
|
||||||
onClick={this.doSave}
|
onClick={this.doSave}
|
||||||
@ -273,7 +284,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!readOnly && !isClosed && (
|
{allowEditing && (
|
||||||
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem", marginLeft: "-18px" }}>
|
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem", marginLeft: "-18px" }}>
|
||||||
<div
|
<div
|
||||||
onClick={this.doClose}
|
onClick={this.doClose}
|
||||||
|
Loading…
Reference in New Issue
Block a user