From: Tim Otten Date: Mon, 21 Jun 2021 00:17:14 +0000 (-0700) Subject: crmMonaco - Add option to receive inserted snippets X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=341a2441ed1d67ffa3575bc25712a4b294dea09f;p=civicrm-core.git crmMonaco - Add option to receive inserted snippets --- diff --git a/ang/crmMonaco.js b/ang/crmMonaco.js index d232391578..3d6ff667f4 100644 --- a/ang/crmMonaco.js +++ b/ang/crmMonaco.js @@ -94,4 +94,19 @@ }; }); + angular.module('crmMonaco').directive('crmMonacoInsertRx', function() { + return { + require: 'crmMonaco', + link: function(scope, element, attrs, crmMonaco) { + scope.$on(attrs.crmMonacoInsertRx, function(e, tokenName) { + var editor = crmMonaco.editor; + var id = { major: 1, minor: 1 }; + var op = {identifier: id, range: editor.getSelection(), text: tokenName, forceMoveMarkers: true}; + editor.executeEdits("tokens", [op]); + editor.focus(); + }); + } + }; + }); + })(angular, CRM.$, CRM._);