* fixed expand issues

* removed expand
This commit is contained in:
anandamarsh
2023-09-05 15:05:18 -07:00
committed by GitHub
parent c81a01aa9c
commit fa04cd9e5c
4 changed files with 43 additions and 46 deletions
+23 -20
View File
@@ -600,31 +600,34 @@ class LineCmd extends React.Component<
}; };
} }
scrollToBringIntoViewport = () => { scrollToBringIntoViewport = (delay = 1) => {
const container = document.getElementsByClassName("lines")[0]; const container = document.getElementsByClassName("lines")[0];
const targetDiv = this.lineRef.current; const targetDiv = this.lineRef.current;
const targetPosition = targetDiv.getBoundingClientRect(); const targetPosition = targetDiv.getBoundingClientRect();
const containerPosition = container.getBoundingClientRect(); const containerPosition = container.getBoundingClientRect();
// Check if the top of the targetDiv is above the container's visible area setTimeout(() => doScroll(), delay);
if (targetPosition.top < containerPosition.top) { const doScroll = () => {
// Scroll up to make the top of the targetDiv visible // Check if the top of the targetDiv is above the container's visible area
const scrollAmount = container.scrollTop + targetPosition.top - containerPosition.top; if (targetPosition.top < containerPosition.top) {
container.scrollTo({ // Scroll up to make the top of the targetDiv visible
top: scrollAmount, const scrollAmount = container.scrollTop + targetPosition.top - containerPosition.top;
behavior: "smooth", container.scrollTo({
}); top: scrollAmount,
} behavior: "smooth",
// Check if the bottom of the targetDiv is below the container's visible area });
else if (targetPosition.bottom > containerPosition.bottom) { }
// Scroll down to make the bottom of the targetDiv visible // Check if the bottom of the targetDiv is below the container's visible area
const scrollAmount = container.scrollTop + targetPosition.bottom - containerPosition.bottom; else if (targetPosition.bottom > containerPosition.bottom) {
container.scrollTo({ // Scroll down to make the bottom of the targetDiv visible
top: scrollAmount, const scrollAmount = container.scrollTop + targetPosition.bottom - containerPosition.bottom;
behavior: "smooth", container.scrollTo({
}); top: scrollAmount,
} behavior: "smooth",
// If both conditions are false, then targetDiv is already fully visible, no scrolling needed });
}
// If both conditions are false, then targetDiv is already fully visible, no scrolling needed
};
}; };
render() { render() {
+3
View File
@@ -276,6 +276,9 @@ input[type="checkbox"] {
background-color: #aaaea7; background-color: #aaaea7;
cursor: default !important; cursor: default !important;
} }
.save-disabled:hover {
background-color: #aaaea7;
}
.message { .message {
color: white; color: white;
border-radius: 6px; border-radius: 6px;
-1
View File
@@ -128,7 +128,6 @@ class SimpleBlobRendererModel {
rtnp.then((file) => { rtnp.then((file) => {
this.readOnly = file.readOnly; this.readOnly = file.readOnly;
this.dataBlob = file; this.dataBlob = file;
console.log("got file", file);
mobx.action(() => { mobx.action(() => {
this.loading.set(false); this.loading.set(false);
this.loadError.set(null); this.loadError.set(null);
+17 -25
View File
@@ -3,12 +3,15 @@ import { RendererContext, RendererOpts, LineStateType } from "../types";
import Editor from "@monaco-editor/react"; import Editor from "@monaco-editor/react";
import { GlobalModel } from "../model"; import { GlobalModel } from "../model";
function renderCmdText(text: string): any {
return <span>&#x2318;{text}</span>;
}
class SourceCodeRenderer extends React.Component< class SourceCodeRenderer extends React.Component<
{ {
data: Blob; data: Blob;
cmdstr: string; cmdstr: string;
cwd: string; cwd: string;
readOnly: boolean;
exitcode: number; exitcode: number;
context: RendererContext; context: RendererContext;
opts: RendererOpts; opts: RendererOpts;
@@ -35,7 +38,6 @@ class SourceCodeRenderer extends React.Component<
language: "", language: "",
languages: [], languages: [],
selectedLanguage: "", selectedLanguage: "",
isFullWindow: false,
isSave: false, isSave: false,
editorHeight: props.savedHeight, editorHeight: props.savedHeight,
message: null, message: null,
@@ -43,6 +45,7 @@ class SourceCodeRenderer extends React.Component<
} }
componentDidMount(): void { componentDidMount(): void {
console.dir(this.props);
this.filePath = this.props.lineState["prompt:file"]; this.filePath = this.props.lineState["prompt:file"];
const { screenId, lineId } = this.props.context; const { screenId, lineId } = this.props.context;
this.cacheKey = `${screenId}-${lineId}-${this.filePath}`; this.cacheKey = `${screenId}-${lineId}-${this.filePath}`;
@@ -58,8 +61,9 @@ class SourceCodeRenderer extends React.Component<
} }
handleEditorDidMount = (editor, monaco) => { handleEditorDidMount = (editor, monaco) => {
const extension = // we try to grab the filename from with filePath (coming from lineState["prompt:file"]) or cmdstr
(this.filePath && this.filePath.match(/(?:[^\\\/:*?"<>|\r\n]+\.)([a-zA-Z0-9]+)\b/)?.[1]) || ""; const strForFilePath = this.filePath || this.props.cmdstr;
const extension = strForFilePath.match(/(?:[^\\\/:*?"<>|\r\n]+\.)([a-zA-Z0-9]+)\b/)?.[1] || "";
const detectedLanguage = monaco.languages const detectedLanguage = monaco.languages
.getLanguages() .getLanguages()
.find((lang) => lang.extensions?.includes("." + extension)); .find((lang) => lang.extensions?.includes("." + extension));
@@ -94,13 +98,6 @@ class SourceCodeRenderer extends React.Component<
} }
}; };
toggleFit = () => {
const isFullWindow = !this.state.isFullWindow;
this.setState({ isFullWindow });
this.setEditorHeight();
setTimeout(() => this.props.scrollToBringIntoViewport(), 350);
};
doSave = () => { doSave = () => {
const { screenId, lineId } = this.props.context; const { screenId, lineId } = this.props.context;
const encodedCode = new TextEncoder().encode(this.state.code); const encodedCode = new TextEncoder().encode(this.state.code);
@@ -121,21 +118,21 @@ class SourceCodeRenderer extends React.Component<
}; };
handleEditorChange = (code) => { handleEditorChange = (code) => {
this.setState({ isFullWindow: true, code });
SourceCodeRenderer.codeCache.set(this.cacheKey, code); SourceCodeRenderer.codeCache.set(this.cacheKey, code);
this.setEditorHeight(); this.setState({ code }, () => {
setTimeout(() => this.props.scrollToBringIntoViewport(), 350); this.setEditorHeight();
this.props.data.text().then((originalCode) => this.setState({ isSave: code !== originalCode })); this.props.data.text().then((originalCode) => this.setState({ isSave: code !== originalCode }));
});
}; };
setEditorHeight = () => { setEditorHeight = () => {
const fullWindowHeight = parseInt(this.props.opts.maxSize.height); const fullWindowHeight = parseInt(this.props.opts.maxSize.height);
let _editorHeight = fullWindowHeight; let _editorHeight = fullWindowHeight;
if (!this.state.isFullWindow) { if (this.props.readOnly) {
const noOfLines = this.state.code.split("\n").length; const noOfLines = this.state.code.split("\n").length;
_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.setState({ editorHeight: _editorHeight }, () => this.props.scrollToBringIntoViewport());
}; };
render() { render() {
@@ -192,7 +189,7 @@ class SourceCodeRenderer extends React.Component<
className="dropdown" className="dropdown"
value={this.state.selectedLanguage} value={this.state.selectedLanguage}
onChange={this.handleLanguageChange} onChange={this.handleLanguageChange}
style={{ minWidth: "6rem", maxWidth: "6rem", marginRight: "8px" }} style={{ minWidth: "6rem", maxWidth: "6rem", marginRight: "26px" }}
> >
{this.state.languages.map((lang, index) => ( {this.state.languages.map((lang, index) => (
<option key={index} value={lang}> <option key={index} value={lang}>
@@ -200,18 +197,13 @@ class SourceCodeRenderer extends React.Component<
</option> </option>
))} ))}
</select> </select>
<div className="cmd-hints" style={{ minWidth: "6rem", maxWidth: "6rem" }}> {!this.props.readOnly && (
<div onClick={this.toggleFit} className="hint-item color-white">
{this.state.isFullWindow ? `shrink` : `expand`}
</div>
</div>
{!this.props.opts.readOnly && (
<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}
className={`hint-item ${isSave ? "save-enabled" : "save-disabled"}`} className={`hint-item ${isSave ? "save-enabled" : "save-disabled"}`}
> >
{"save"} {`save`} {renderCmdText("S")}
</div> </div>
</div> </div>
)} )}