fix all typescript errors (#18)

This commit is contained in:
sawka 2023-09-07 12:57:02 -07:00 committed by GitHub
parent baeafdce78
commit 7376ed2824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 22 deletions

View File

@ -97,7 +97,7 @@ class SimpleBlobRendererModel {
this.reload_noDelay();
} else {
setTimeout(() => {
reload_noDelay();
this.reload_noDelay();
}, delayMs);
}
}
@ -126,7 +126,7 @@ class SimpleBlobRendererModel {
}
let rtnp = GlobalModel.readRemoteFile(this.context.screenId, this.context.lineId, path);
rtnp.then((file) => {
this.readOnly = file.readOnly;
this.readOnly = (file as any).readOnly;
this.dataBlob = file;
mobx.action(() => {
this.loading.set(false);

View File

@ -357,7 +357,6 @@ type RendererOpts = {
idealSize: WindowSize;
termOpts: TermOptsType;
termFontSize: number;
readOnly: boolean;
};
type RendererOptsUpdate = {
@ -410,11 +409,16 @@ type RendererModel = {
};
type SimpleBlobRendererComponent = React.ComponentType<{
path: string;
data: Blob;
readOnly?: boolean;
cmdstr?: string;
cwd?: string;
exitcode?: number;
context: RendererContext;
opts: RendererOpts;
savedHeight: number;
scrollToBringIntoViewport?: () => void;
lineState?: LineStateType;
}>;
type FullRendererComponent = React.ComponentType<{ model: any }>;

View File

@ -9,9 +9,13 @@ function renderCmdText(text: string): any {
return <span>&#x2318;{text}</span>;
}
// there is a global monaco variable (TODO get the correct TS type)
declare var monaco: any;
class SourceCodeRenderer extends React.Component<
{
data: Blob;
readOnly: boolean;
cmdstr: string;
cwd: string;
exitcode: number;
@ -21,7 +25,15 @@ class SourceCodeRenderer extends React.Component<
scrollToBringIntoViewport: () => void;
lineState: LineStateType;
},
{}
{
code: string;
languages: string[];
selectedLanguage: string;
isSave: boolean;
isClosed: boolean;
editorHeight: number;
message: { status: string; text: string };
}
> {
/**
* codeCache is a Hashmap with key=screenId:lineId:filepath and value=code
@ -32,9 +44,11 @@ class SourceCodeRenderer extends React.Component<
filePath;
cacheKey;
originalData;
monacoEditor: any; // reference to mounted monaco editor. TODO need the correct type
constructor(props) {
super(props);
this.editorRef = React.createRef();
this.monacoEditor = null;
this.state = {
code: null,
languages: [],
@ -86,7 +100,6 @@ class SourceCodeRenderer extends React.Component<
}
}
if (detectedLanguage) {
this.editorRef.current = editor;
const model = editor.getModel();
if (model) {
monaco.editor.setModelLanguage(model, detectedLanguage);
@ -96,6 +109,7 @@ class SourceCodeRenderer extends React.Component<
};
handleEditorDidMount = (editor, monaco) => {
this.monacoEditor = editor;
this.setInitialLanguage(editor);
this.setEditorHeight();
editor.onKeyDown((e) => {
@ -114,8 +128,8 @@ class SourceCodeRenderer extends React.Component<
const { screenId, lineId } = this.props.context;
const selectedLanguage = event.target.value;
this.setState({ selectedLanguage });
if (this.editorRef.current) {
const model = this.editorRef.current.getModel();
if (this.monacoEditor) {
const model = this.monacoEditor.getModel();
if (model) {
monaco.editor.setModelLanguage(model, selectedLanguage);
GlobalCommandRunner.setLineState(
@ -184,7 +198,7 @@ class SourceCodeRenderer extends React.Component<
};
setEditorHeight = () => {
const fullWindowHeight = parseInt(this.props.opts.maxSize.height);
const fullWindowHeight = this.props.opts.maxSize.height;
let _editorHeight = fullWindowHeight;
if (this.props.readOnly || this.state.isClosed) {
const noOfLines = Math.max(this.state.code.split("\n").length, 5);
@ -195,7 +209,7 @@ class SourceCodeRenderer extends React.Component<
render() {
const { opts, exitcode, readOnly } = this.props;
const { language, code, isSave, isClosed } = this.state;
const { selectedLanguage, code, isSave, isClosed } = this.state;
if (code == null)
return <div className="renderer-container code-renderer" style={{ height: this.props.savedHeight }} />;
@ -220,7 +234,7 @@ class SourceCodeRenderer extends React.Component<
<Editor
theme="hc-black"
height={this.state.editorHeight}
defaultLanguage={language}
defaultLanguage={selectedLanguage}
defaultValue={code}
onMount={this.handleEditorDidMount}
options={{
@ -228,16 +242,6 @@ class SourceCodeRenderer extends React.Component<
fontSize: GlobalModel.termFontSize.get(),
fontFamily: "JetBrains Mono",
readOnly: readOnly || isClosed,
keybindings: [
{
key: "ctrl+s",
command: "-editor.action.filesave",
},
{
key: "cmd+s",
command: "-editor.action.filesave",
},
],
}}
onChange={this.handleEditorChange}
/>