How to disable the autocomplete macros keyboard shortcuts, "{" and "!"?

Trying to reduce users’ reliance on macros, per customer request. The requirement targets the “{” and the “!” keyboard shortcuts. I need users to only access macros through the “+” button on the editor toolbar.

So far, the following jQuery code has not worked. The code is located on the Custom HTML head section.

AJS.toInit(function(){
 AJS.$("#d").keypress(function (e) {
 
 var charTyped = String.fromCharCode(e.which);
 if (charTyped == "{" || charTyped == "!") {
 
 e.preventDefault();

 var sel = window.getSelection();
 if (sel.rangeCount > 0) {
 
 var range = sel.getRangeAt(0);
 range.deleteContents();

 
 var text = (charTyped == ")") ? "{}" : "()";
 var textNode = document.createTextNode(text);
 range.insertNode(textNode);

 
 range.setStart(textNode, 1);
 range.setEnd(textNode, 1);
 sel.removeAllRanges();
 sel.addRange(range);
 }
 }


 });
 });

I believe Confluence has an override in place on anything affecting the RTE. The code works on JSbin, on a regular HTML, CSS, JS page. However, this code does not have the same effect on the RTE.

I know, you can disable the autocomplete feature from each user’s settings account. Then again, if you are trying to provide a solution for more than 20 users, going through each user account is an administrative nightmare. Also, switching this feature off disables other autocomplete actions like “@”, for linking users, and “//”, for adding a date.

What piece of the puzzle am I missing?

1 Like