code: function _getNextMatch(editor, searchBackwards, pos, wrap) {
          var cm = editor._codeMirror;
          var state = getSearchState(cm);
          var cursor = getSearchCursor(cm, state, pos || editor.getCursorPos(false, searchBackwards ? "start" : "end"));
  
          state.lastMatch = cursor.find(searchBackwards);
          if (!state.lastMatch && wrap !== false) {
              // If no result found before hitting edge of file, try wrapping around
              cursor = getSearchCursor(cm, state, searchBackwards ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});
              state.lastMatch = cursor.find(searchBackwards);
          }
          if (!state.lastMatch) {
              // No result found, period: clear selection & bail
              cm.setCursor(editor.getCursorPos());  // collapses selection, keeping cursor in place to avoid scrolling
              return null;
          }
  
          return {start: cursor.from(), end: cursor.to()};
      }
docs: @private
  Returns the next match for the current query (from the search state) before/after the given position. Wraps around
  the end of the document if no match is found before the end.
  
  @param {!Editor} editor The editor to search in
  @param {boolean} searchBackwards true to search backwards
  @param {{line: number, ch: number}=} pos The position to start from. Defaults to the current primary selection's
  head cursor position.
  @param {boolean=} wrap Whether to wrap the search around if we hit the end of the document. Default true.
  @return {?{start: {line: number, ch: number}, end: {line: number, ch: number}}} The range for the next match, or
  null if there is no match.