mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
4341d35304
commit
74ebf2393d
@ -60,7 +60,7 @@ export const defaultEditorProps: Partial<MonacoEditorProps> = {
|
||||
options: {},
|
||||
language: "yaml",
|
||||
autoFocus: false,
|
||||
get theme(): string {
|
||||
get theme(): MonacoEditorProps["theme"] {
|
||||
// theme for monaco-editor defined in `src/renderer/themes/lens-*.json`
|
||||
return ThemeStore.getInstance().activeTheme.monacoTheme;
|
||||
}
|
||||
@ -147,24 +147,30 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.createEditor();
|
||||
logger.info(`[MONACO]: editor did mounted`);
|
||||
|
||||
if (this.props.autoFocus) {
|
||||
this.editor.focus();
|
||||
try {
|
||||
this.createEditor();
|
||||
if (this.props.autoFocus) {
|
||||
this.editor.focus();
|
||||
}
|
||||
logger.info(`[MONACO]: editor did mounted`);
|
||||
} catch (error) {
|
||||
logger.error(`[MONACO]: mounting failed`, { error, editor: this });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
logger.info(`[MONACO]: unmounting editor..`);
|
||||
this.unmounting = true;
|
||||
this.disposeOnUnmount();
|
||||
MonacoEditor.models.get(this).forEach(model => model.dispose());
|
||||
MonacoEditor.models.delete(this);
|
||||
this.editor?.dispose();
|
||||
try {
|
||||
logger.info(`[MONACO]: unmounting editor..`);
|
||||
this.unmounting = true;
|
||||
this.destroyEditor();
|
||||
MonacoEditor.models.get(this).forEach(model => model.dispose());
|
||||
MonacoEditor.models.delete(this);
|
||||
} catch (error) {
|
||||
logger.error(`[MONACO]: unmounting error failed: ${String(error)}`, this, error);
|
||||
}
|
||||
}
|
||||
|
||||
private createEditor = (): void => {
|
||||
private createEditor() {
|
||||
if (!this.containerElem || this.editor || this.unmounting) {
|
||||
return;
|
||||
}
|
||||
@ -210,6 +216,14 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
||||
);
|
||||
};
|
||||
|
||||
private destroyEditor(): void {
|
||||
if (!this.editor) return;
|
||||
|
||||
this.editor.dispose();
|
||||
this.editor = null;
|
||||
this.disposeOnUnmount();
|
||||
}
|
||||
|
||||
@action
|
||||
setDimensions(width: number, height: number) {
|
||||
this.dimensions.width = width;
|
||||
|
||||
@ -26,6 +26,7 @@ import logger from "../main/logger";
|
||||
import darkTheme from "./themes/lens-dark.json";
|
||||
import lightTheme from "./themes/lens-light.json";
|
||||
import type { SelectOption } from "./components/select";
|
||||
import type { MonacoEditorProps } from "./components/monaco-editor";
|
||||
|
||||
export type ThemeId = string;
|
||||
|
||||
@ -35,7 +36,7 @@ export interface Theme {
|
||||
colors: Record<string, string>;
|
||||
description: string;
|
||||
author: string;
|
||||
monacoTheme: string;
|
||||
monacoTheme: MonacoEditorProps["theme"];
|
||||
}
|
||||
|
||||
export interface ThemeItems extends Theme {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user