code: function getMacroMatch (ctx, macros) {
              var selected, path = [], offset;
  
              if (selectedElementIsTextAreaOrInput(ctx)) {
                  selected = getDocument(ctx).activeElement;
              } else {
                  // content editable
                  var selectionInfo = getContentEditableSelectedPath(ctx);
                  if (selectionInfo) {
                      selected = selectionInfo.selected;
                      path = selectionInfo.path;
                      offset = selectionInfo.offset;
                  }
              }
              var effectiveRange = getTextPrecedingCurrentSelection(ctx);
              if (effectiveRange !== undefined && effectiveRange !== null) {
  
                  var matchInfo;
  
                  var hasTrailingSpace = false;
  
                  if (effectiveRange.length > 0 &&
                      (effectiveRange.charAt(effectiveRange.length - 1) === '\xA0' ||
                          effectiveRange.charAt(effectiveRange.length - 1) === ' ')) {
                      hasTrailingSpace = true;
                      // strip space
                      effectiveRange = effectiveRange.substring(0, effectiveRange.length-1);
                  }
  
                  angular.forEach(macros, function (macro, c) {
                      var idx = effectiveRange.toUpperCase().lastIndexOf(c.toUpperCase());
  
                      if (idx >= 0 && c.length + idx === effectiveRange.length) {
                          var prevCharPos = idx - 1;
                          if (idx === 0 || effectiveRange.charAt(prevCharPos) === '\xA0' ||
                              effectiveRange.charAt(prevCharPos) === ' ' ) {
  
                              matchInfo = {
                                  macroPosition: idx,
                                  macroText: c,
                                  macroSelectedElement: selected,
                                  macroSelectedPath: path,
                                  macroSelectedOffset: offset,
                                  macroHasTrailingSpace: hasTrailingSpace
                              };
                          }
                      }
                  });
                  if (matchInfo) {
                      return matchInfo;
                  }
              }
          }
docs: public