@@ -219,12 +219,47 @@ export default {
219219 return true ;
220220 },
221221 addNewRuleToModeler (newRule ) {
222- this .modelerRestrictedLanguage += ' \n ' + newRule;
223- // check if the new rule is an initial rule
224222 if (newRule .startsWith (' Initially start' )) {
225-
226- } else if (newRule .endsWith (' the process finishes.' )) { // check if the new rule is a final rule
227-
223+ // initial rule
224+ let edited = false ;
225+ for (let i = 0 ; i < this .modelerRestrictedLanguage .split (' \n ' ).length ; i++ ) {
226+ if (this .modelerRestrictedLanguage .split (' \n ' )[i].startsWith (' Initially start' )) {
227+ let lines = this .modelerRestrictedLanguage .split (' \n ' );
228+ lines[i] = newRule;
229+ this .modelerRestrictedLanguage = lines .join (' \n ' );
230+ edited = true ;
231+ break ;
232+ }
233+ }
234+ if (! edited) {
235+ this .modelerRestrictedLanguage += ' \n ' + newRule;
236+ }
237+ } else if (newRule .endsWith (' the process finishes.' )) {
238+ // check if the new rule is a final rule
239+ let edited = false ;
240+ for (let i = 0 ; i < this .modelerRestrictedLanguage .split (' \n ' ).length ; i++ ) {
241+ if (this .modelerRestrictedLanguage .split (' \n ' )[i].endsWith (' the process finishes.' )) {
242+ let lines = this .modelerRestrictedLanguage .split (' \n ' );
243+ lines[i] = newRule;
244+ this .modelerRestrictedLanguage = lines .join (' \n ' );
245+ edited = true ;
246+ break ;
247+ }
248+ }
249+ if (! edited) {
250+ this .modelerRestrictedLanguage += ' \n ' + newRule;
251+ }
252+ } else {
253+ // other rules
254+ // add the new rule just before the final rule
255+ let lines = this .modelerRestrictedLanguage .split (' \n ' );
256+ let finalRuleIndex = lines .findIndex (line => line .endsWith (' the process finishes.' ));
257+ if (finalRuleIndex !== - 1 ) {
258+ lines .splice (finalRuleIndex, 0 , newRule);
259+ } else {
260+ lines .push (newRule);
261+ }
262+ this .modelerRestrictedLanguage = lines .join (' \n ' );
228263 }
229264 }
230265 },
0 commit comments