mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
detach dock-store imports from monaco-editor.tsx
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
0f4301a5a3
commit
65aadbac52
@ -29,7 +29,6 @@ import ReactMonacoEditor, { EditorDidMount, MonacoEditorProps } from "react-mona
|
|||||||
import { ThemeStore } from "../../theme.store";
|
import { ThemeStore } from "../../theme.store";
|
||||||
import { UserStore } from "../../../common/user-store";
|
import { UserStore } from "../../../common/user-store";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
import { dockStore } from "../dock/dock.store";
|
|
||||||
|
|
||||||
interface Props extends MonacoEditorProps {
|
interface Props extends MonacoEditorProps {
|
||||||
id?: string; // associate editor's model.uri with some ID (e.g. DockStore.TabId)
|
id?: string; // associate editor's model.uri with some ID (e.g. DockStore.TabId)
|
||||||
@ -65,7 +64,6 @@ export class MonacoEditor extends React.Component<Props> {
|
|||||||
|
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => this.model, this.onModelChange),
|
reaction(() => this.model, this.onModelChange),
|
||||||
dockStore.onTabChange(() => this.saveViewState()), // backup cursor position, etc.
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.whenReady.then(() => this.bindResizeObserver());
|
this.whenReady.then(() => this.bindResizeObserver());
|
||||||
@ -98,6 +96,7 @@ export class MonacoEditor extends React.Component<Props> {
|
|||||||
|
|
||||||
onModelChange = (model: monaco.editor.ITextModel, oldModel?: monaco.editor.ITextModel) => {
|
onModelChange = (model: monaco.editor.ITextModel, oldModel?: monaco.editor.ITextModel) => {
|
||||||
logger.info("[MONACO]: model change", { model, oldModel });
|
logger.info("[MONACO]: model change", { model, oldModel });
|
||||||
|
this.saveViewState(oldModel); // save previously used view-model state
|
||||||
this.editor.setModel(model);
|
this.editor.setModel(model);
|
||||||
this.editor.restoreViewState(this.getViewState(model));
|
this.editor.restoreViewState(this.getViewState(model));
|
||||||
this.editor.layout();
|
this.editor.layout();
|
||||||
@ -144,9 +143,9 @@ export class MonacoEditor extends React.Component<Props> {
|
|||||||
return MonacoEditor.viewStates.get(model) ?? null;
|
return MonacoEditor.viewStates.get(model) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveViewState(model = this.model, state = this.editor.saveViewState()) {
|
saveViewState(model = this.model) {
|
||||||
if (!model || !state) return;
|
if (!model) return;
|
||||||
MonacoEditor.viewStates.set(model, state);
|
MonacoEditor.viewStates.set(model, this.editor.saveViewState());
|
||||||
}
|
}
|
||||||
|
|
||||||
getModelById(id: string): monaco.editor.ITextModel | null {
|
getModelById(id: string): monaco.editor.ITextModel | null {
|
||||||
@ -182,8 +181,7 @@ export class MonacoEditor extends React.Component<Props> {
|
|||||||
readOnly,
|
readOnly,
|
||||||
...globalOptions,
|
...globalOptions,
|
||||||
...options,
|
...options,
|
||||||
}}
|
}}/>
|
||||||
/>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user