From 0b59d25a53c1de4d152aade320c7c78e7ce9d01e Mon Sep 17 00:00:00 2001 From: Luc Patiny Date: Thu, 27 Nov 2025 09:20:17 +0100 Subject: [PATCH 1/3] test: check if reaction editor trigger a variable change on load --- package-lock.json | 4 +- .../openchemlib-reaction-inplace/view.json | 136 +++++++++++++++++- 2 files changed, 137 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index db387f2f3..4679f9d65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "visualizer", - "version": "2.175.3", + "version": "2.175.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "visualizer", - "version": "2.175.3", + "version": "2.175.4", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/testcase/data/openchemlib-reaction-inplace/view.json b/testcase/data/openchemlib-reaction-inplace/view.json index c249e9777..ab2b90248 100644 --- a/testcase/data/openchemlib-reaction-inplace/view.json +++ b/testcase/data/openchemlib-reaction-inplace/view.json @@ -1,5 +1,5 @@ { - "version": "2.173.4-0", + "version": "2.175.5-0", "grid": { "layers": { "Default layer": { @@ -943,6 +943,140 @@ } ], "title": "We pretend it is a V3000 but in fact we check in place modification" + }, + { + "url": "modules/types/client_interaction/code_executor/", + "configuration": { + "sections": {}, + "groups": { + "group": [ + { + "display": [ + [ + "editor", + "buttons" + ] + ], + "execOnLoad": [ + [] + ], + "asyncAwait": [ + [ + "top" + ] + ], + "script": [ + "console.log('Variable changed: '+this.variable)" + ] + } + ], + "libs": [ + [ + {} + ] + ], + "buttons": [ + [ + { + "name": "button1", + "label": "Execute", + "hide": [], + "disable": [] + } + ] + ] + } + }, + "layers": { + "Default layer": { + "position": { + "left": 42, + "top": 42 + }, + "size": { + "width": 46, + "height": 35 + }, + "zIndex": 0, + "display": true, + "title": "", + "bgColor": [ + 255, + 255, + 255, + 0 + ], + "wrapper": true, + "created": true, + "name": "Default layer" + } + }, + "id": 8, + "vars_in": [ + { + "rel": "inputValue", + "name": "rxnV2000" + }, + { + "rel": "inputValue", + "name": "rxnV3000" + }, + { + "rel": "inputValue", + "name": "smiles" + } + ], + "actions_in": [ + {} + ], + "vars_out": [ + { + "jpath": [] + } + ], + "actions_out": [ + { + "jpath": [] + } + ], + "toolbar": { + "custom": [ + [ + { + "title": "", + "icon": "", + "action": "", + "position": "begin", + "color": [ + 100, + 100, + 100, + 1 + ] + } + ] + ], + "common": [ + { + "toolbar": [ + [ + "Open Preferences" + ] + ] + } + ] + }, + "css": [ + { + "fontSize": [ + "" + ], + "fontFamily": [ + "" + ] + } + ], + "title": "" } ], "variables": [], From 778f7049edd1610d73e53597c53a2e8aeffa60da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 27 Nov 2025 11:05:20 +0100 Subject: [PATCH 2/3] update OCL --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4679f9d65..75dfe6c96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "mf-parser": "^1.5.0", "mime-types": "^2.1.35", "node-jsgraph": "2.4.15", - "openchemlib": "^9.18.0", + "openchemlib": "^9.18.2", "quill": "2.0.2", "quill-resize-module": "^2.0.4", "quill-table-better": "^1.2.1", @@ -6834,9 +6834,9 @@ } }, "node_modules/openchemlib": { - "version": "9.18.0", - "resolved": "https://registry.npmjs.org/openchemlib/-/openchemlib-9.18.0.tgz", - "integrity": "sha512-RokrwMkEIaY3fya6RkmvT5xyVQAq5VqZrMYp1qBpE4xFyqyko+ziVA5DXoEN1B2OLiRyHkW/FRHBXKt4t7YxpQ==", + "version": "9.18.2", + "resolved": "https://registry.npmjs.org/openchemlib/-/openchemlib-9.18.2.tgz", + "integrity": "sha512-amgDEgH7lLOBGg3sS2XmxjY+n6zC8M+ohJqNgifKACkbjPuzmnzs85rbMHcAndMzn7e6hh7IwJ8FByWKdBhGSg==", "license": "BSD-3-Clause" }, "node_modules/optionator": { diff --git a/package.json b/package.json index 7be3b1566..92ab0b84c 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "mf-parser": "^1.5.0", "mime-types": "^2.1.35", "node-jsgraph": "2.4.15", - "openchemlib": "^9.18.0", + "openchemlib": "^9.18.2", "quill": "2.0.2", "quill-resize-module": "^2.0.4", "quill-table-better": "^1.2.1", From 6b49072757c39ace5fb0f9743f5eb7d41d745b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 27 Nov 2025 11:13:01 +0100 Subject: [PATCH 3/3] fix: only emit OCL editor changes when event is from user and updates the molecule/reaction --- .../types/science/chemistry/ocl_editor/controller.js | 1 + src/modules/types/science/chemistry/ocl_editor/view.js | 7 ++++--- .../science/chemistry/ocl_reaction_editor/controller.js | 1 + .../types/science/chemistry/ocl_reaction_editor/view.js | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/types/science/chemistry/ocl_editor/controller.js b/src/modules/types/science/chemistry/ocl_editor/controller.js index b9f01cf42..396cc5fba 100644 --- a/src/modules/types/science/chemistry/ocl_editor/controller.js +++ b/src/modules/types/science/chemistry/ocl_editor/controller.js @@ -160,6 +160,7 @@ define([ }; Controller.prototype.onChange = function (event, molecule) { + if (!event.isUserEvent) return; const inPlace = this.module.getConfigurationCheckbox('prefs', 'inPlace'); // In modify variable in mode diff --git a/src/modules/types/science/chemistry/ocl_editor/view.js b/src/modules/types/science/chemistry/ocl_editor/view.js index c1ebf939d..2290df08f 100644 --- a/src/modules/types/science/chemistry/ocl_editor/view.js +++ b/src/modules/types/science/chemistry/ocl_editor/view.js @@ -130,9 +130,10 @@ define(['modules/default/defaultview', 'src/util/ui', 'openchemlib'], function ( initEditor() { const controller = this.module.controller; this.editor = new OCL.CanvasEditor(this.dom.get(0)); - this.editor.setOnChangeListener((event) => - controller.onChange(event, this.editor.getMolecule()), - ); + this.editor.setOnChangeListener((event) => { + if (event.type !== 'molecule') return; + controller.onChange(event, this.editor.getMolecule()); + }); this.editor.setMolecule( OCL.Molecule.fromIDCode( controller.currentMol.idCode, diff --git a/src/modules/types/science/chemistry/ocl_reaction_editor/controller.js b/src/modules/types/science/chemistry/ocl_reaction_editor/controller.js index 413f68d27..4766cfaf4 100644 --- a/src/modules/types/science/chemistry/ocl_reaction_editor/controller.js +++ b/src/modules/types/science/chemistry/ocl_reaction_editor/controller.js @@ -135,6 +135,7 @@ define([ }; Controller.prototype.onChange = function (event, reaction) { + if (!event.isUserEvent) return; const inPlace = this.module.getConfigurationCheckbox('prefs', 'inPlace'); const idCode = OCL.ReactionEncoder.encode(reaction) || ''; const rxn = reaction.toRxn(); diff --git a/src/modules/types/science/chemistry/ocl_reaction_editor/view.js b/src/modules/types/science/chemistry/ocl_reaction_editor/view.js index 47d3d5f30..6a6b0726f 100644 --- a/src/modules/types/science/chemistry/ocl_reaction_editor/view.js +++ b/src/modules/types/science/chemistry/ocl_reaction_editor/view.js @@ -98,6 +98,7 @@ define(['modules/default/defaultview', 'src/util/ui', 'openchemlib'], function ( initialMode: 'reaction', }); this.editor.setOnChangeListener((event) => { + if (event.type !== 'molecule') return; const reaction = this.editor.getReaction(); this._currentReaction = reaction; this.module.controller.onChange(event, reaction);