crmMonaco - Add option to receive inserted snippets
authorTim Otten <totten@civicrm.org>
Mon, 21 Jun 2021 00:17:14 +0000 (17:17 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 6 Jul 2021 21:34:18 +0000 (14:34 -0700)
ang/crmMonaco.js

index d23239157844605732e6eaea46e2750d4f7bd091..3d6ff667f4c0f81d43cfad3ca013d9c2911778e7 100644 (file)
     };
   });
 
+  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._);