1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-10-02 17:50:39 +03:00
parent 4341d35304
commit 74ebf2393d
2 changed files with 29 additions and 14 deletions

View File

@ -60,7 +60,7 @@ export const defaultEditorProps: Partial<MonacoEditorProps> = {
options: {}, options: {},
language: "yaml", language: "yaml",
autoFocus: false, autoFocus: false,
get theme(): string { get theme(): MonacoEditorProps["theme"] {
// theme for monaco-editor defined in `src/renderer/themes/lens-*.json` // theme for monaco-editor defined in `src/renderer/themes/lens-*.json`
return ThemeStore.getInstance().activeTheme.monacoTheme; return ThemeStore.getInstance().activeTheme.monacoTheme;
} }
@ -147,24 +147,30 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
} }
componentDidMount() { componentDidMount() {
this.createEditor(); try {
logger.info(`[MONACO]: editor did mounted`); this.createEditor();
if (this.props.autoFocus) {
if (this.props.autoFocus) { this.editor.focus();
this.editor.focus(); }
logger.info(`[MONACO]: editor did mounted`);
} catch (error) {
logger.error(`[MONACO]: mounting failed`, { error, editor: this });
} }
} }
componentWillUnmount() { componentWillUnmount() {
logger.info(`[MONACO]: unmounting editor..`); try {
this.unmounting = true; logger.info(`[MONACO]: unmounting editor..`);
this.disposeOnUnmount(); this.unmounting = true;
MonacoEditor.models.get(this).forEach(model => model.dispose()); this.destroyEditor();
MonacoEditor.models.delete(this); MonacoEditor.models.get(this).forEach(model => model.dispose());
this.editor?.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) { if (!this.containerElem || this.editor || this.unmounting) {
return; 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 @action
setDimensions(width: number, height: number) { setDimensions(width: number, height: number) {
this.dimensions.width = width; this.dimensions.width = width;

View File

@ -26,6 +26,7 @@ import logger from "../main/logger";
import darkTheme from "./themes/lens-dark.json"; import darkTheme from "./themes/lens-dark.json";
import lightTheme from "./themes/lens-light.json"; import lightTheme from "./themes/lens-light.json";
import type { SelectOption } from "./components/select"; import type { SelectOption } from "./components/select";
import type { MonacoEditorProps } from "./components/monaco-editor";
export type ThemeId = string; export type ThemeId = string;
@ -35,7 +36,7 @@ export interface Theme {
colors: Record<string, string>; colors: Record<string, string>;
description: string; description: string;
author: string; author: string;
monacoTheme: string; monacoTheme: MonacoEditorProps["theme"];
} }
export interface ThemeItems extends Theme { export interface ThemeItems extends Theme {