Skip to content

Commit f99ffb2

Browse files
committed
Fixed bug with SetTriggerOption and re-evaluating triggers
1 parent 39cce14 commit f99ffb2

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

scripting/methods/methods_triggers.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ bool bReplace = false;
188188

189189
t_regexp * regexp = NULL;
190190

191-
CString strRegexp;
191+
CString strRegexp;
192192

193193
if (Flags & eTriggerRegularExpression)
194194
strRegexp = MatchText;
195195
else
196196
strRegexp = ConvertToRegularExpression (MatchText);
197197

198198
// compile regular expression
199-
try
199+
try
200200
{
201201
regexp = regcomp (strRegexp, (Flags & eIgnoreCase ? PCRE_CASELESS : 0) | (m_bUTF_8 ? PCRE_UTF8 : 0));
202202
} // end of try
@@ -752,6 +752,46 @@ bool bChanged;
752752
if (TriggerOptionsTable [iItem].iFlags & OPT_CANNOT_WRITE)
753753
return ePluginCannotSetOption; // not available for writing at all
754754

755+
// ------ preliminary validation before setting the option
756+
757+
if (strOptionName == "multi_line" ||
758+
strOptionName == "ignore_case")
759+
{
760+
t_regexp * regexp = NULL;
761+
762+
CString strRegexp;
763+
764+
if (trigger_item->bRegexp)
765+
strRegexp = trigger_item->trigger;
766+
else
767+
strRegexp = ConvertToRegularExpression (trigger_item->trigger);
768+
769+
// compile regular expression
770+
try
771+
{
772+
// use new options as appropriate
773+
unsigned short bMultiLine = trigger_item->bMultiLine;
774+
if (strOptionName == "multi_line")
775+
bMultiLine = iValue;
776+
unsigned short bIgnoreCase = trigger_item->ignore_case;
777+
if (strOptionName == "ignore_case")
778+
bIgnoreCase = iValue;
779+
780+
regexp = regcomp (strRegexp, (bIgnoreCase ? PCRE_CASELESS : 0) |
781+
(bMultiLine ? PCRE_MULTILINE : 0) |
782+
(m_bUTF_8 ? PCRE_UTF8 : 0)
783+
);
784+
} // end of try
785+
catch(CException* e)
786+
{
787+
e->Delete ();
788+
return eBadRegularExpression;
789+
} // end of catch
790+
791+
delete trigger_item->regexp; // get rid of old one
792+
trigger_item->regexp = regexp;
793+
} // end of option multi_line or ignore_case
794+
755795
iResult = SetBaseOptionItem (iItem,
756796
TriggerOptionsTable,
757797
NUMITEMS (TriggerOptionsTable),
@@ -790,9 +830,7 @@ bool bChanged;
790830
// ------ preliminary validation before setting the option
791831

792832
// cannot have null match text
793-
if (strOptionName == "match" ||
794-
strOptionName == "ignore_case" ||
795-
strOptionName == "multi_line")
833+
if (strOptionName == "match")
796834
{
797835
if (strValue.IsEmpty ())
798836
return eTriggerCannotBeEmpty;

0 commit comments

Comments
 (0)