Skip to content

Commit c4d4543

Browse files
lpatinytargos
andauthored
fix: only emit OCL editor changes when event is from user and updates the molecule/reaction
* test: check if reaction editor trigger a variable change on load * update OCL * fix: only emit OCL editor changes when event is from user and updates the molecule/reaction --------- Co-authored-by: Michaël Zasso <targos@protonmail.com>
1 parent bffae1e commit c4d4543

File tree

7 files changed

+149
-11
lines changed

7 files changed

+149
-11
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"mf-parser": "^1.5.0",
8383
"mime-types": "^2.1.35",
8484
"node-jsgraph": "2.4.15",
85-
"openchemlib": "^9.18.0",
85+
"openchemlib": "^9.18.2",
8686
"quill": "2.0.2",
8787
"quill-resize-module": "^2.0.4",
8888
"quill-table-better": "^1.2.1",

src/modules/types/science/chemistry/ocl_editor/controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ define([
160160
};
161161

162162
Controller.prototype.onChange = function (event, molecule) {
163+
if (!event.isUserEvent) return;
163164
const inPlace = this.module.getConfigurationCheckbox('prefs', 'inPlace');
164165

165166
// In modify variable in mode

src/modules/types/science/chemistry/ocl_editor/view.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ define(['modules/default/defaultview', 'src/util/ui', 'openchemlib'], function (
130130
initEditor() {
131131
const controller = this.module.controller;
132132
this.editor = new OCL.CanvasEditor(this.dom.get(0));
133-
this.editor.setOnChangeListener((event) =>
134-
controller.onChange(event, this.editor.getMolecule()),
135-
);
133+
this.editor.setOnChangeListener((event) => {
134+
if (event.type !== 'molecule') return;
135+
controller.onChange(event, this.editor.getMolecule());
136+
});
136137
this.editor.setMolecule(
137138
OCL.Molecule.fromIDCode(
138139
controller.currentMol.idCode,

src/modules/types/science/chemistry/ocl_reaction_editor/controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ define([
135135
};
136136

137137
Controller.prototype.onChange = function (event, reaction) {
138+
if (!event.isUserEvent) return;
138139
const inPlace = this.module.getConfigurationCheckbox('prefs', 'inPlace');
139140
const idCode = OCL.ReactionEncoder.encode(reaction) || '';
140141
const rxn = reaction.toRxn();

src/modules/types/science/chemistry/ocl_reaction_editor/view.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ define(['modules/default/defaultview', 'src/util/ui', 'openchemlib'], function (
9898
initialMode: 'reaction',
9999
});
100100
this.editor.setOnChangeListener((event) => {
101+
if (event.type !== 'molecule') return;
101102
const reaction = this.editor.getReaction();
102103
this._currentReaction = reaction;
103104
this.module.controller.onChange(event, reaction);

testcase/data/openchemlib-reaction-inplace/view.json

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.173.4-0",
2+
"version": "2.175.5-0",
33
"grid": {
44
"layers": {
55
"Default layer": {
@@ -943,6 +943,140 @@
943943
}
944944
],
945945
"title": "We pretend it is a V3000 but in fact we check in place modification"
946+
},
947+
{
948+
"url": "modules/types/client_interaction/code_executor/",
949+
"configuration": {
950+
"sections": {},
951+
"groups": {
952+
"group": [
953+
{
954+
"display": [
955+
[
956+
"editor",
957+
"buttons"
958+
]
959+
],
960+
"execOnLoad": [
961+
[]
962+
],
963+
"asyncAwait": [
964+
[
965+
"top"
966+
]
967+
],
968+
"script": [
969+
"console.log('Variable changed: '+this.variable)"
970+
]
971+
}
972+
],
973+
"libs": [
974+
[
975+
{}
976+
]
977+
],
978+
"buttons": [
979+
[
980+
{
981+
"name": "button1",
982+
"label": "Execute",
983+
"hide": [],
984+
"disable": []
985+
}
986+
]
987+
]
988+
}
989+
},
990+
"layers": {
991+
"Default layer": {
992+
"position": {
993+
"left": 42,
994+
"top": 42
995+
},
996+
"size": {
997+
"width": 46,
998+
"height": 35
999+
},
1000+
"zIndex": 0,
1001+
"display": true,
1002+
"title": "",
1003+
"bgColor": [
1004+
255,
1005+
255,
1006+
255,
1007+
0
1008+
],
1009+
"wrapper": true,
1010+
"created": true,
1011+
"name": "Default layer"
1012+
}
1013+
},
1014+
"id": 8,
1015+
"vars_in": [
1016+
{
1017+
"rel": "inputValue",
1018+
"name": "rxnV2000"
1019+
},
1020+
{
1021+
"rel": "inputValue",
1022+
"name": "rxnV3000"
1023+
},
1024+
{
1025+
"rel": "inputValue",
1026+
"name": "smiles"
1027+
}
1028+
],
1029+
"actions_in": [
1030+
{}
1031+
],
1032+
"vars_out": [
1033+
{
1034+
"jpath": []
1035+
}
1036+
],
1037+
"actions_out": [
1038+
{
1039+
"jpath": []
1040+
}
1041+
],
1042+
"toolbar": {
1043+
"custom": [
1044+
[
1045+
{
1046+
"title": "",
1047+
"icon": "",
1048+
"action": "",
1049+
"position": "begin",
1050+
"color": [
1051+
100,
1052+
100,
1053+
100,
1054+
1
1055+
]
1056+
}
1057+
]
1058+
],
1059+
"common": [
1060+
{
1061+
"toolbar": [
1062+
[
1063+
"Open Preferences"
1064+
]
1065+
]
1066+
}
1067+
]
1068+
},
1069+
"css": [
1070+
{
1071+
"fontSize": [
1072+
""
1073+
],
1074+
"fontFamily": [
1075+
""
1076+
]
1077+
}
1078+
],
1079+
"title": ""
9461080
}
9471081
],
9481082
"variables": [],

0 commit comments

Comments
 (0)