Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Move question of re-init to function isReInitRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Nov 9, 2023
1 parent d71c97e commit bdd2f0b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "monaco-editor-wrapper-examples",
"private": true,
"version": "3.4.0-next.2",
"version": "3.4.0-next.3",
"type": "module",
"dependencies": {
"@codingame/monaco-vscode-configuration-service-override": "~1.83.5",
"@codingame/monaco-vscode-editor-service-override": "~1.83.5",
"@codingame/monaco-vscode-json-default-extension": "~1.83.5",
"@codingame/monaco-vscode-keybindings-service-override": "~1.83.5",
"@codingame/monaco-vscode-python-default-extension": "~1.83.5",
"@typefox/monaco-editor-react": "~2.4.0-next.2",
"@typefox/monaco-editor-react": "~2.4.0-next.3",
"http-server": "~14.1.1",
"langium": "~2.1.1",
"langium-statemachine-dsl": "~2.1.0",
"monaco-editor": "npm:@codingame/monaco-editor-treemended@>=1.83.5 <1.84.0",
"monaco-editor-workers": "~0.44.0",
"monaco-editor-wrapper": "~3.4.0-next.2",
"monaco-editor-wrapper": "~3.4.0-next.3",
"monaco-languageclient": "~7.0.0",
"monaco-languageclient-examples": "~7.0.0",
"react": "~18.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/monaco-editor-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typefox/monaco-editor-react",
"version": "2.4.0-next.2",
"version": "2.4.0-next.3",
"license": "MIT",
"description": "React component for Monaco-Editor and Monaco Languageclient",
"keywords": [
Expand Down Expand Up @@ -51,12 +51,12 @@
},
"dependencies": {
"monaco-editor": "npm:@codingame/monaco-editor-treemended@>=1.83.5 <1.84.0",
"monaco-editor-wrapper": "~3.4.0-next.2",
"monaco-editor-wrapper": "~3.4.0-next.3",
"react": "~18.2.0",
"vscode": "npm:@codingame/monaco-vscode-api@>=1.83.5 <1.84.0"
},
"peerDependencies": {
"monaco-editor-wrapper": "~3.4.0-next.2"
"monaco-editor-wrapper": "~3.4.0-next.3"
},
"devDependencies": {
"@types/react": "~18.2.37"
Expand Down
37 changes: 24 additions & 13 deletions packages/monaco-editor-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ export class MonacoEditorReactComp<T extends MonacoEditorProps = MonacoEditorPro
}

override async componentDidUpdate(prevProps: T) {
const { userConfig } = this.props;
const { wrapper } = this;

const mustReInit = this.isReInitRequired(prevProps);

if (mustReInit) {
await this.handleReinit();
} else {
// the function now ensure a model update is only required if something else than the code changed
this.wrapper.updateModel(userConfig.wrapperConfig.editorAppConfig);

const config = userConfig.wrapperConfig.editorAppConfig;
const prevConfig = prevProps.userConfig.wrapperConfig.editorAppConfig;
if (prevConfig.$type === 'classic' && config.$type === 'classic') {
if (prevConfig.editorOptions !== config.editorOptions) {
(wrapper.getMonacoEditorApp() as EditorAppClassic).updateMonacoEditorOptions(config.editorOptions ?? {});
}
}
}
}

protected isReInitRequired(prevProps: T) {
const { className, userConfig } = this.props;
const { wrapper } = this;

Expand All @@ -43,8 +65,8 @@ export class MonacoEditorReactComp<T extends MonacoEditorProps = MonacoEditorPro
}

let mustReInit = false;
const prevConfig = prevProps.userConfig.wrapperConfig.editorAppConfig;
const config = userConfig.wrapperConfig.editorAppConfig;
const prevConfig = prevProps.userConfig.wrapperConfig.editorAppConfig;
const prevWorkerOptions = prevProps.userConfig.languageClientConfig?.options;
const currentWorkerOptions = userConfig.languageClientConfig?.options;
const prevIsWorker = (prevWorkerOptions?.$type === 'WorkerDirect');
Expand All @@ -69,18 +91,7 @@ export class MonacoEditorReactComp<T extends MonacoEditorProps = MonacoEditorPro
mustReInit = (wrapper?.getMonacoEditorApp() as EditorAppExtended).isAppConfigDifferent(prevConfig, config, false) === true;
}

if (mustReInit) {
await this.handleReinit();
} else {
// the function now ensure a model update is only required if something else than the code changed
this.wrapper.updateModel(userConfig.wrapperConfig.editorAppConfig);

if (prevConfig.$type === 'classic' && config.$type === 'classic') {
if (prevConfig.editorOptions !== config.editorOptions) {
(wrapper.getMonacoEditorApp() as EditorAppClassic).updateMonacoEditorOptions(config.editorOptions ?? {});
}
}
}
return mustReInit;
}

override componentWillUnmount() {
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-editor-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monaco-editor-wrapper",
"version": "3.4.0-next.2",
"version": "3.4.0-next.3",
"license": "MIT",
"description": "Monaco-Editor and Monaco Languageclient Wrapper",
"keywords": [
Expand Down

0 comments on commit bdd2f0b

Please sign in to comment.